12 ms c++ solution


  • 0
    B
    void isValidHelper(TreeNode* root, bool& is_valid, long& low){
            
            if(root == NULL){
                return;
            }
            
            isValidHelper(root->left,is_valid,low);
            
            if(low < root->val){
                low = root->val;
            }
            else{
                is_valid = false;
                return;
            }
            
            isValidHelper(root->right,is_valid,low);
            
        }
    
        bool isValidBST(TreeNode* root) {
            
            bool is_valid = true;
            long low = LONG_MIN;
            
            isValidHelper(root,is_valid,low);
            
            return is_valid;
            
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.