Update 0098.验证二叉搜索树,添加C#版

This commit is contained in:
eeee0717
2023-11-28 10:17:25 +08:00
parent ca89ca3097
commit 7aef42def8

View File

@ -791,6 +791,20 @@ impl Solution {
}
}
```
### C#
```C#
// 递归
public long val = Int64.MinValue;
public bool IsValidBST(TreeNode root)
{
if (root == null) return true;
bool left = IsValidBST(root.left);
if (root.val > val) val = root.val;
else return false;
bool right = IsValidBST(root.right);
return left && right;
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">