/** * 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; } return isValid(root, Long.MIN_VALUE, Long.MAX_VALUE); } public boolean isValid(TreeNode node, long lower, long larger) { if (node == null) { return true; } if (node.val <= lower || node.val >= larger) { return false; } return isValid(node.left, lower, node.val) && isValid(node.right,node.val, larger); } }
标签:node,right,TreeNode,val,二叉,力扣,98,return,left From: https://www.cnblogs.com/JavaYuYin/p/18018322