-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsolution.py
35 lines (32 loc) · 933 Bytes
/
solution.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
#!/usr/bin/env python
# Created by Bruce yuan on 18-2-6.
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def levelOrderBottom(self, root):
"""
做了上面这个之后,竟然一次就过了2333,哈哈哈
:type root: TreeNodes
:rtype: List[List[int]]
"""
if root == None:
return []
ans = []
import queue
q = queue.Queue()
q.put(root)
while not q.empty():
tmp = []
for _ in range(q.qsize()):
item = q.get()
tmp.append(item.val)
if item.left is not None:
q.put(item.left)
if item.right is not None:
q.put(item.right)
ans.insert(0, tmp)
return ans