SHARE
TWEET

Untitled

a guest Jun 12th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top