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

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_112._Path_Sum</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

9
112. Path Sum/Program.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace _112._Path_Sum;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}

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;
}
}

16
112. Path Sum/TreeNode.cs Normal file
View File

@@ -0,0 +1,16 @@
namespace _112._Path_Sum;
//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;
}
}