diff --git a/csharp/112-Path-Sum.cs b/csharp/112-Path-Sum.cs new file mode 100644 index 000000000..9f47fba48 --- /dev/null +++ b/csharp/112-Path-Sum.cs @@ -0,0 +1,24 @@ +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution { + public bool HasPathSum(TreeNode root, int targetSum) { + if(root == null) return false; + if(root.left == null && root.right == null) + return targetSum == root.val; + + return + HasPathSum(root.left, targetSum - root.val) || + HasPathSum(root.right, targetSum - root.val); + } +} \ No newline at end of file