-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path366.py
33 lines (30 loc) · 881 Bytes
/
366.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
#366
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def findLeaves(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
res = []
final_res = []
def dfs(node):
if not node:
return
if node:
if not node.left and not node.right:
res.append(node.val)
return None
node.left = dfs(node.left)
node.right = dfs(node.right)
return node
while (root):
root = dfs(root)
final_res.append(res)
res =[]
return final_res