mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
36 lines
1.2 KiB
HTML
36 lines
1.2 KiB
HTML
|
<p>给你一个二叉树的根节点 <code>root</code> ,判断其是否是一个有效的二叉搜索树。</p>
|
|||
|
|
|||
|
<p><strong>有效</strong> 二叉搜索树定义如下:</p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>节点的左子树只包含<strong> 小于 </strong>当前节点的数。</li>
|
|||
|
<li>节点的右子树只包含 <strong>大于</strong> 当前节点的数。</li>
|
|||
|
<li>所有左子树和右子树自身必须也是二叉搜索树。</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg" style="width: 302px; height: 182px;" />
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>root = [2,1,3]
|
|||
|
<strong>输出:</strong>true
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg" style="width: 422px; height: 292px;" />
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>root = [5,1,4,null,null,3,6]
|
|||
|
<strong>输出:</strong>false
|
|||
|
<strong>解释:</strong>根节点的值是 5 ,但是右子节点的值是 4 。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>树中节点数目范围在<code>[1, 10<sup>4</sup>]</code> 内</li>
|
|||
|
<li><code>-2<sup>31</sup> <= Node.val <= 2<sup>31</sup> - 1</code></li>
|
|||
|
</ul>
|