-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path94.linningmii.py
36 lines (30 loc) · 886 Bytes
/
94.linningmii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def inorderTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
result = []
cur_node = root
stack = []
still_has_node = True
while still_has_node:
if cur_node is None:
if len(stack) == 0:
still_has_node = False
continue
else:
pop_up_node = stack.pop(0)
result.append(pop_up_node.val)
cur_node = pop_up_node.right
continue
else:
stack.insert(0, cur_node)
cur_node = cur_node.left
return result