Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def inorderTraversal(self, root: TreeNode) -> List[int]:
- if not root:
- return []
- stack = [root]
- res = []
- while len(stack) > 0:
- curr_node = stack.pop()
- if len(stack) > 0 and stack[len(stack) - 1] is None:
- res.append(curr_node.val)
- stack.pop()
- else:
- if curr_node.right:
- stack.append(curr_node.right)
- stack.append(None)
- stack.append(curr_node)
- if curr_node.left:
- stack.append(curr_node.left)
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement