```
class Solution {
public:
int maxSubArray(int A[], int n) {
int max = A[0], sum = 0;
for(int i = 0; i < n; i++){
sum += A[i];
if(max < sum)
max = sum;
if(sum < 0)
sum = 0;
}
return max;
}
};
```