Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. class Solution:
  2.     def inorderTraversal(self, root: TreeNode) -> List[int]:
  3.         if not root:
  4.             return []
  5.         stack = [root]
  6.         res = []
  7.         while len(stack) > 0:
  8.             curr_node = stack.pop()
  9.             if len(stack) > 0 and stack[len(stack) - 1] is None:
  10.                 res.append(curr_node.val)
  11.                 stack.pop()
  12.             else:
  13.                 if curr_node.right:
  14.                     stack.append(curr_node.right)
  15.                 stack.append(None)
  16.                 stack.append(curr_node)
  17.                
  18.                 if curr_node.left:
  19.                     stack.append(curr_node.left)
  20.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement