题目
题目链接
解题思路
相关代码
class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<>();
Stack<TreeNode> stack = new Stack<>();
while(stack.size()!=0||root!=null){
while(root!=null){
stack.push(root);
root=root.left;
}
TreeNode temp = stack.pop();
list.add(temp.val);
root=temp.right;
}
return list;
}
}