We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 31e308e commit 1d5315cCopy full SHA for 1d5315c
solution/0112.Path Sum/Solution.java
@@ -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