Skip to content

Commit f2a9ab4

Browse files
committed
112. Path Sum
1 parent e05ff6c commit f2a9ab4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

(#112)PathSum/(#112)PathSum.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public boolean hasPathSum(TreeNode root, int sum) {
3+
if(root == null)
4+
return false;
5+
if(root.left == null && root.right == null && sum - root.val == 0)
6+
return true;
7+
8+
return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
9+
}
10+
11+
}

0 commit comments

Comments
 (0)