This commit is contained in:
Electrominch
2022-10-11 01:45:16 +03:00
parent c019e8856c
commit 02afed9c4c
34 changed files with 691 additions and 3 deletions

View File

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

View File

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

View File

@@ -0,0 +1,21 @@
namespace _98._Validate_Binary_Search_Tree;
public class Solution
{
public bool IsValidBST(TreeNode root)
{
return Rec(root, null, null);
}
private bool Rec(TreeNode node, int? lessThan, int? moreThan)
{
if((lessThan != null && node.val >= lessThan) || (moreThan != null && node.val <= moreThan))
return false;
bool res = true;
if(node.left != null)
res&=Rec(node.left, node.val, moreThan);
if(node.right != null)
res &=Rec(node.right, lessThan, node.val);
return res;
}
}

View File

@@ -0,0 +1,16 @@
namespace _98._Validate_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;
}
}