File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
src/com/leetcode/submissions Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 23
23
| 剑指 Offer 26| [ 树的子结构] ( # ) | [ Java] ( ./src/com/leetcode/submissions/IsSubStructure.java ) | Medium|
24
24
| 剑指 Offer 55 - II| [ 平衡二叉树] ( # ) | [ Java] ( ./src/com/leetcode/submissions/IsBalanced.java ) | Easy|
25
25
| 814 | [ 二叉树剪枝] ( # ) | [ Java] ( ./src/com/leetcode/submissions/BinaryTreePruning.java ) | Medium|
26
+ | 面试题 04.05| [ 合法二叉搜索树] ( # ) | [ Java] ( ./src/com/leetcode/submissions/IsValidBST.java ) | Medium|
26
27
27
28
28
29
## 题目目录
Original file line number Diff line number Diff line change
1
+ package com .leetcode .submissions ;
2
+
3
+ import com .leetcode .extend .TreeNode ;
4
+
5
+ /**
6
+ * 面试题 04.05. 合法二叉搜索树
7
+ * Create by Ranzd on 2021-01-25 20:18
8
+ *
9
+
10
+ */
11
+ public class IsValidBST {
12
+ public long MAX_VAL = Long .MIN_VALUE ;
13
+
14
+ public boolean isValidBST (TreeNode root ) {
15
+ if (root == null ) {
16
+ return true ;
17
+ }
18
+ boolean left = isValidBST (root .left );
19
+ if (!left ) {
20
+ return false ;
21
+ }
22
+ if (MAX_VAL >= root .val ) {
23
+ return false ;
24
+ }
25
+ MAX_VAL = root .val ;
26
+ return isValidBST (root .right );
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments