1 public class Solution { 2 public ArrayList<Integer> inorderTraversal(TreeNode root) { 3 ArrayList<Integer> res = new ArrayList<Integer> (); 4 Stack<TreeNode> stack = new Stack<TreeNode>(); 5 TreeNode cur = root; 6 while(!stack.isEmpty()||cur!=null){ 7 if(cur!=null){ 8 stack.push(cur); 9 cur = cur.left; 10 } 11 else{ 12 cur = stack.pop(); 13 res.add(cur.val); 14 cur = cur.right; 15 } 16 } 17 return res; 18 } 19 }
相关文章
- 12-21Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
- 12-21Binary Tree Inorder Traversal
- 12-21LeetCode Binary Tree Preorder Traversal 先根遍历
- 12-21【LeetCode】297. Serialize and Deserialize Binary Tree 解题报告(Python)
- 12-21Binary Tree HDU - 5573 (思维)
- 12-21【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)
- 12-21103. Binary Tree Zigzag Level Order Traversal
- 12-21LeetCode不定时刷题——Convert Sorted Array to Binary Search Tree
- 12-21LeetCode 199: Binary Tree Right Side View
- 12-21[Algo] 140. Maximum Path Sum Binary Tree III