Day i do not know

This commit is contained in:
Electrominch
2022-10-18 00:45:31 +03:00
parent 01c5720116
commit 284b6ff10c
72 changed files with 1256 additions and 12 deletions

21
112. Path Sum/Solution.cs Normal file
View File

@@ -0,0 +1,21 @@
namespace _112._Path_Sum;
public class Solution
{
public bool HasPathSum(TreeNode root, int targetSum)
=> root != null ? Recursion(root, root.val, targetSum) : false;
private bool Recursion(TreeNode? node, int curSum, int targetSum)
{
if (curSum == targetSum && node != null && node.left == null && node.right == null)
return true;
if (node == null)
return false;
bool res = false;
if(node.left != null)
res |= Recursion(node.left, curSum + node.left.val, targetSum);
if (node.right != null)
res |= Recursion(node.right, curSum + node.right.val, targetSum);
return res;
}
}