Update 0098.验证二叉搜索树,添加C#版
This commit is contained in:
parent
ca89ca3097
commit
7aef42def8
|
|
@ -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">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue