本文共 622 字,大约阅读时间需要 2 分钟。
思路:
何时为一个合格的搜索树? 1左边是合格搜索树 2右边是合格搜索树 3根大于左边的最大值 4根小于右边的最小值运用递归判断
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean isValidBST(TreeNode root) { if(root==null) { return true; } boolean left=true; boolean right=true; if(root.left!=null) { left=isValidBST(root.left)&&root.val>getmax(root.left); } if(root.right!=null) { right=isValidBST(root.right)&&root.val
转载地址:http://pcuvb.baihongyu.com/