Validate Binary Search Tree

给一个二叉树, 问是不是bst. 就利用bst的性质验证.

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    double lastval = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root == null)
            return true;
        if(!isValidBST(root.left))
            return false;
        if(lastval>=root.val)
            return false;
        lastval = root.val;
        if(!isValidBST(root.right))
            return false;
        return true;
    }
}