/*
 * public class TreeNode {
 *   int val = 0;
 *   TreeNode left = null;
 *   TreeNode right = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param root TreeNode类 the root
     * @return bool布尔型一维数组
     */
    public boolean[] judgeIt (TreeNode root) {
        // write code here
     
        boolean isSearchTree = isSearchTree(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
        boolean isFullTree = isFullTree(root);
        return new boolean[]{isSearchTree, isFullTree};
    }
    private boolean isFullTree(TreeNode root){
        if(root == null){
            return true;
        }
        Queue<TreeNode> queue = new LinkedList<TreeNode>();
        queue.offer(root);
        while(queue.peek() != null){
            TreeNode node =queue.poll();
            queue.offer(node.left);
            queue.offer(node.right);
        }
        while(!queue.isEmpty() && queue.peek() == null){
            queue.poll();
        }
        return queue.isEmpty();
    }
    
    //左子树 都要比这个节点小,右子树都要大
    private boolean isSearchTree(TreeNode node, int min, int max){
        if(node == null){
            return true;
        }
        if(node.val <= min ||node.val >= max){
            return false;
        }
        return isSearchTree(node.left, min, node.val) && isSearchTree(node.right, node.val, max);
    }
}