一、题目
二、代码
/**
* 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
{
List<Integer> re = new LinkedList<>();
public boolean isValidBST(TreeNode root)
{
mid(root);
int i;
int length = re.size();
for(i=1;i<length;i++)
{
if(re.get(i-1)>=re.get(i)) return false;
}
return true;
}
public void mid(TreeNode cur)
{
if(cur.left!=null) mid(cur.left);
re.add(cur.val);
if(cur.right!=null) mid(cur.right);
}
}