Untitled
unknown
plain_text
10 months ago
483 B
5
Indexable
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.add(root);
root = root.left;
}
root = stack.pop();
list.add(root.val);
root = root.right;
}
return list;
}Editor is loading...
Leave a Comment