-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path68.py
33 lines (29 loc) · 773 Bytes
/
68.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
"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
"""
class Solution:
"""
@param root: A Tree
@return: Postorder in ArrayList which contains node values.
"""
def postorderTraversal(self, root):
# write your code here
if not root:
return []
res = []
stack1 = []
stack2 = []
stack1.append(root)
while stack1:
node = stack1.pop()
if node:
stack1.append(node.left)
stack1.append(node.right)
stack2.append(node.val)
while stack2:
res.append(stack2.pop())
return res