Skip to content

Commit f14ae04

Browse files
author
Joseph Luce
authored
Update 094_binary_tree_inorder_traversal.md
1 parent 57420fc commit f14ae04

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

leetcode/medium/094_binary_tree_inorder_traversal.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ class Solution:
4747
def inorderTraversal(self, root: TreeNode) -> List[int]:
4848
stack, result = list(), list()
4949
curr_node = root
50-
while True:
51-
if curr_node is not None: # Going down the tree
50+
while stack or curr_node:
51+
if curr_node:
5252
stack.append(curr_node)
53-
curr_node = curr_node.left
54-
elif len(stack) > 0: # Going up the tree (backtracking)
55-
curr_node = stack.pop()
56-
result.append(curr_node.val)
57-
curr_node = curr_node.right
53+
curr_node = curr_node.left # go left
5854
else:
59-
break
55+
curr_node = stack.pop() # go up
56+
result.append(curr_node.val)
57+
curr_node = curr_node.right # go right
6058
return result
6159
```

0 commit comments

Comments
 (0)