[second]Validate Binary Search Tree

 

    bool isValidBST(TreeNode *root) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        return helper(root,INT_MIN,INT_MAX);
        
    }
    
    bool helper(TreeNode* root,int lower,int upper)
    {
        if(!root)
            return true;
        if(root->val<=lower||root->val>=upper)
            return false;
        
        return helper(root->left,lower,root->val)&&helper(root->right,root->val,upper);
        
    }

  

posted @ 2013-10-03 23:26  summer_zhou  阅读(128)  评论(0编辑  收藏  举报