forked from yingl/LintCodeInPython
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree_paths.py
More file actions
Latest commit
21 lines (19 loc) · 709 Bytes
/
Copy pathbinary_tree_paths.py
File metadata and controls
21 lines (19 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-
classSolution:
# @param {TreeNode} root the root of the binary tree
# @return {List[str]} all root-to-leaf paths
defbinaryTreePaths(self, root):
# Write your code here
self.ret= []
self._binaryTreePaths(root, '')
returnself.ret
def_binaryTreePaths(self, root, path):
ifroot:
path+=str(root.val) ifnotpathelse ('->'+str(root.val))
# print path
ifroot.left:
self._binaryTreePaths(root.left, path)
ifroot.right:
self._binaryTreePaths(root.right, path)
ifnot (root.leftorroot.right):
self.ret.append(path)