Skip to content

Commit 00daed7

Browse files
(Failed)Path_Sum
1 parent 2f9f55a commit 00daed7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

112(Failed)_Path_Sum.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def hasPathSum(self, root, sum):
10+
"""
11+
:type root: TreeNode
12+
:type sum: int
13+
:rtype: bool
14+
"""
15+
if None == root:
16+
return False
17+
elif None == root.left and None == root.right:
18+
return sum == root.val
19+
else:
20+
return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val)

0 commit comments

Comments
 (0)