We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eacd882 commit fc8127fCopy full SHA for fc8127f
1 file changed
java/Tree/Path Sum
@@ -0,0 +1,23 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * int val;
5
+ * TreeNode left;
6
+ * TreeNode right;
7
+ * TreeNode() {}
8
+ * TreeNode(int val) { this.val = val; }
9
+ * TreeNode(int val, TreeNode left, TreeNode right) {
10
+ * this.val = val;
11
+ * this.left = left;
12
+ * this.right = right;
13
+ * }
14
15
+ */
16
+class Solution {
17
+ public boolean hasPathSum(TreeNode root, int targetSum) {
18
+ if (root == null) return false;
19
+ if(root.left == null && root.right == null && root.val == targetSum) return true;
20
+ return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);
21
+ }
22
+
23
+}
0 commit comments