There are already multiple explanations. Just adding my solution as well as it seemed fairly clean:

```
int maxSubArray(int A[], int n) {
int best = A[0];
int current = A[0];
for (int i = 1; i < n; i++) {
current = max(current + A[i], A[i]);
best = max(current, best);
}
return best;
}
```