Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 8 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /