(TreeNode root)
| 1 | class Solution { |
| 2 | public List<Integer> inorderTraversal(TreeNode root) { |
| 3 | Stack<TreeNode> stack = new Stack<TreeNode>(); |
| 4 | List<Integer> inOrder = new ArrayList<Integer>(); |
| 5 | if(root==null) return inOrder; |
| 6 | while(true) |
| 7 | { |
| 8 | if(root!=null) |
| 9 | { |
| 10 | stack.push(root); |
| 11 | root=root.left; |
| 12 | } |
| 13 | else |
| 14 | { |
| 15 | if(stack.isEmpty()) break; |
| 16 | root=stack.pop(); |
| 17 | inOrder.add(root.val); |
| 18 | root=root.right; |
| 19 | } |
| 20 | } |
| 21 | return inOrder; |
| 22 | |
| 23 | } |
| 24 | } |
| 25 |