Skip to content

Commit 7e32d47

Browse files
(Failed)_Binary_Tree_Level_Order_Traversal ||
1 parent 22dbee3 commit 7e32d47

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def levelOrderBottom(self, root):
10+
"""
11+
:type root: TreeNode
12+
:rtype: List[List[int]]
13+
"""
14+
ans = []
15+
def bfs(root, level):
16+
if root != None:
17+
if len(ans) < level + 1:
18+
ans.append([])
19+
ans[level].append(root.val)
20+
bfs(root.left, level + 1)
21+
bfs(root.right, level + 1)
22+
bfs(root, 0)
23+
ans.reverse()
24+
return ans

0 commit comments

Comments
 (0)