@@ -9,65 +9,87 @@ tree (BST)_.
99
1010A ** valid BST** is defined as follows:
1111
12- - The left subtree of a node contains only nodes with keys ** less than** the node's key.
13- - The right subtree of a node contains only nodes with keys ** greater than** the node's key.
14- - Both the left and right subtrees must also be binary search trees.
12+ * The left subtree of a node contains only nodes with keys ** less than** the node's key.
13+ * The right subtree of a node contains only nodes with keys ** greater than** the node's key.
14+ * Both the left and right subtrees must also be binary search trees.
15+
16+
1517
1618** Example 1:**
1719
1820![ ] ( https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg )
1921
2022> Input: root = [ 2,1,3]
21- >
23+ >
2224> Output: true
2325
2426** Example 2:**
2527
2628![ ] ( https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg )
2729
2830> Input: root = [ 5,1,4,null,null,3,6]
29- >
31+ >
3032> Output: false
31- >
33+ >
3234> Explanation: The root node's value is 5 but its right child's value is 4.
3335
3436** Constraints:**
3537
36- - The number of nodes in the tree is in the range ` [1, 10^4] ` .
37- - ` -231 <= Node.val <= 231 - 1 `
38+ * The number of nodes in the tree is in the range ` [1, 104] ` .
39+ * ` -231 <= Node.val <= 231 - 1 `
40+
3841
3942## 题目大意
4043
4144给你一个二叉树的根节点 ` root ` ,判断其是否是一个有效的二叉搜索树。
4245
4346** 有效** 二叉搜索树定义如下:
4447
45- - 节点的左子树只包含** 小于** 当前节点的数。
46- - 节点的右子树只包含 ** 大于** 当前节点的数。
47- - 所有左子树和右子树自身必须也是二叉搜索树。
48+ * 节点的左子树只包含** 小于** 当前节点的数。
49+ * 节点的右子树只包含 ** 大于** 当前节点的数。
50+ * 所有左子树和右子树自身必须也是二叉搜索树。
51+
52+
4853
4954** 示例 1:**
5055
5156![ ] ( https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg )
5257
58+ >
59+ >
60+ >
61+ >
62+ >
5363> ** 输入:** root = [ 2,1,3]
54- >
64+ >
5565> ** 输出:** true
66+ >
67+ >
5668
5769** 示例 2:**
5870
5971![ ] ( https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg )
6072
73+ >
74+ >
75+ >
76+ >
77+ >
6178> ** 输入:** root = [ 5,1,4,null,null,3,6]
62- >
79+ >
6380> ** 输出:** false
64- >
81+ >
6582> ** 解释:** 根节点的值是 5 ,但是右子节点的值是 4 。
83+ >
84+ >
85+
86+
6687
6788** 提示:**
6889
69- - 树中节点数目范围在` [1, 10^4] ` 内
70- - ` -231 <= Node.val <= 231 - 1 `
90+ * 树中节点数目范围在` [1, 104] ` 内
91+ * ` -231 <= Node.val <= 231 - 1 `
92+
7193
7294## 解题思路
7395
0 commit comments