Skip to content

Commit 413ec73

Browse files
committed
2019-11-19
1 parent ed63eba commit 413ec73

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode(object):
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution(object):
9+
def findLeaves(self, root):
10+
"""
11+
:type root: TreeNode
12+
:rtype: List[List[int]]
13+
"""
14+
from collections import defaultdict
15+
self.dic = defaultdict(list)
16+
res = []
17+
def get_Height(node):
18+
if not node:
19+
return -1
20+
lh = get_Height(node.left)
21+
rh = get_Height(node.right)
22+
h = max(lh, rh) + 1
23+
self.dic[h].append(node.val)
24+
return h
25+
26+
get_Height(root)
27+
# print self.dic
28+
h = 0
29+
while 1:
30+
if h not in self.dic:
31+
break
32+
res.append(self.dic[h])
33+
h += 1
34+
return res
35+

0 commit comments

Comments
 (0)