We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 98b6666 + c588795 commit 6046afeCopy full SHA for 6046afe
csharp/112-Path-Sum.cs
@@ -0,0 +1,24 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * public int val;
5
+ * public TreeNode left;
6
+ * public TreeNode right;
7
+ * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
8
+ * this.val = val;
9
+ * this.left = left;
10
+ * this.right = right;
11
+ * }
12
13
+ */
14
+public class Solution {
15
+ public bool HasPathSum(TreeNode root, int targetSum) {
16
+ if(root == null) return false;
17
+ if(root.left == null && root.right == null)
18
+ return targetSum == root.val;
19
+
20
+ return
21
+ HasPathSum(root.left, targetSum - root.val) ||
22
+ HasPathSum(root.right, targetSum - root.val);
23
+ }
24
+}
0 commit comments