- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPrintAllPath.py
More file actions
Latest commit
20 lines (20 loc) · 476 Bytes
/
Copy pathPrintAllPath.py
File metadata and controls
20 lines (20 loc) · 476 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
classNode(object):
def__init__(self,val=None,left=None,right=None):
self.val=val
self.left=left
self.right=right
'''
print all the path of a binary tree from root to the leaf
'''
paths= []
defAllPaths(root,paths):
'''
Args: root node of a binary tree
Return: list of all the path from the root to the leaf
'''
ifrootisNone:
returnpaths
ifroot.leftisNoneandroot.rightisNone:
paths.append(root.val)
else:
path.