-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path94.py
More file actions
29 lines (25 loc) · 675 Bytes
/
Copy path94.py
File metadata and controls
29 lines (25 loc) · 675 Bytes
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
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
stack = []
res = []
p = root
while p or stack:
while p:
stack.append(p)
p = p.left
if stack:
p = stack.pop()
res.append(p.val)
p = p.right
return res