mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Update 0098.验证二叉搜索树,添加C#版
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user