```
public class Solution {
public int maxSubArray(int[] nums) {
int n = nums.length;
int[] mem = new int[n];
int max = nums[0];
mem[0] = nums[0];
for (int i = 1; i < n; i++){
if(nums[i] > nums[i] + mem[i-1]) mem[i] = nums[i];
else mem[i] = nums[i] + mem[i-1];
if(max < mem[i]) max = mem[i];
}
return max;
}
}
```