Very confused with my C++ code,what is wrong with that ,help!


  • 0
    S
    class Solution {
    public:
        bool isValidBST(TreeNode * root) {
            if(root==NULL)return true;
            if(root->left=NULL && root->right==NULL)return true;
            return dfs(root,LONG_MIN,LONG_MAX);
        }
    private:
        bool dfs(TreeNode * root,long low,long high)
        {
            if(root==NULL)return true;
            return (root->val > low) && (root->val < high) && dfs(root->left,low,root->val) && dfs(root->right,root->val,high);
        }
    };

  • 0
    A

    if(root->left=NULL && root->right==NULL)

    Should be (root->left==NULL) dude...


  • 0
    S

    Oh, very thank.I thought there was something wrong with my algorithm...Thank you~~


Log in to reply
 

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