Skip to content

Commit 1d5315c

Browse files
112. Path Sum (java)
1 parent 31e308e commit 1d5315c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

solution/0112.Path Sum/Solution.java

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

0 commit comments

Comments
 (0)