C++,beat100%,13line simple solution


  • 0
    W
    class Solution {
    public:
        int maxSubArray(vector<int>& nums) {
            int sum=0x80000000,max=0x80000000;
            for(auto i:nums){
                max=sum>max?sum:max;
                if(sum<0){
                    sum=sum>i?sum:i;
                    continue;
                } 
                sum=sum+i>0?sum+i:0;
            }
            return max>sum?max:sum;
        }
    };
    

Log in to reply
 

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