Skip to content

Commit fa67f08

Browse files
author
Chris Wu
committed
no message
1 parent 39d651a commit fa67f08

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Pre-order traversal means that: visit the current node; if there is a left node, visit it; then if there is right node, visit it.
3+
In-order: Left->Current->Right
4+
Pre-order: Current->Left->Right
5+
Post-order: Left->Right->Current
6+
"""
7+
class Solution(object):
8+
def preorder(self, root):
9+
def helper(node):
10+
if not node: return
11+
opt.append(node.val)
12+
for child in node.children:
13+
helper(child)
14+
opt = []
15+
helper(root)
16+
return opt

0 commit comments

Comments
 (0)