Simplest solution O(n) using c++


#1

int Solution::maxSubArray(const vector &A) {
int sum = 0;
int maxsum = INT_MIN;
for(int i = 0;i<A.size();i++)
{
sum+=A[i];

    if(sum>maxsum)
      maxsum = sum;
    if(sum<0)
      sum = 0;
    
}
return maxsum;

}