```
class Solution {
public:
int maxSubArray(vector<int>& nums) {
if (nums.empty())
return 0;
int acc = max(0, nums[0]), sum = nums[0];
for (int i = 1; i < nums.size(); i++) {
sum = max(sum, acc + nums[i]);
acc = max(0, acc + nums[i]);
}
return sum;
}
};
```