leetcode 98验证二叉搜索树,我的思路为什么这个测试案例不通过?
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public boolean isValidBST(TreeNode root) {
if(root == null)
return true;
if(root.left != null && root.left.val >= root.val) {
return false;
}
if(root.right != null && root.right.val <= root.val) {
return false;
}
return isValidBST(root.left) && isValidBST(root.right);
}
}