Need Help! Why the runtime Error Occur?


  • 0
    F

    It says that "reference binding to null pointer of type 'int' ".
    But I never use any size() function , so why ? Your answer will be appreciated!


       TreeNode* constructMaximumBinaryTree(vector<int>& nums) {        
         vector<int>::iterator biggest = std::max_element(std::begin(nums), std::end(nums)); 
            TreeNode root(*biggest) ;
            if (nums.empty() ) return NULL;  // end point 
            vector<int> left (nums.begin() , biggest);
            vector<int> right (biggest+1, nums.end());
    
            root.left = constructMaximumBinaryTree(left);
            root.right = constructMaximumBinaryTree(right);
            return &root ; 
            
        }
    


Log in to reply
 

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