```
public int maxSubArray(int[] nums) {
int max = nums[0];
int maxSoFar = max;
for(int i=1;i<nums.length;i++){
max = max < 0 ? nums[i] : nums[i]+max;
maxSoFar = Math.max(maxSoFar, max);
}
return maxSoFar;
}
```