You should consider the solution that all the numbers in array are negative.

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