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>_700._Search_in_a_Binary_Search_Tree</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

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

View File

@@ -0,0 +1,22 @@
namespace _700._Search_in_a_Binary_Search_Tree;
public class Solution
{
public TreeNode? SearchBST(TreeNode? root, int val)
{
Stack<TreeNode> stack = new Stack<TreeNode>();
if (root != null)
stack.Push(root);
while (stack.Count > 0)
{
TreeNode cur = stack.Pop();
if (cur.right != null)
stack.Push(cur.right);
if (cur.left != null)
stack.Push(cur.left);
if(cur.val == val)
return cur;
}
return null;
}
}

View File

@@ -0,0 +1,15 @@
namespace _700._Search_in_a_Binary_Search_Tree;
//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;
}
}