Easy c++ 6 lines code


  • 0
    G
    int maxSubArray(vector<int>& nums) {
            int sum=0,len=nums.size(),ans,ind;
            if(len==0) return -1;
            ans=nums[0];
            for(ind=0;ind<len;ind++)
            {
                sum = max(sum+nums[ind],nums[ind]);
                ans = max(ans,sum);
            }
            return ans;
        }

Log in to reply
 

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