1. 程式人生 > >94. Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal

cnblogs val new nor code left pub node list

public class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<Integer>();
        Stack<TreeNode> stack=new Stack<TreeNode>();
        while(root!=null||!stack.isEmpty())
        {
            while(root!=null
) { stack.push(root); root=root.left; } root=stack.pop(); res.add(root.val); root=root.right; } return res; } }

94. Binary Tree Inorder Traversal