```
public int maxSubArray(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int max = nums[0];
int maxSum = nums[0];
for (int i = 1; i < nums.length; i++) {
maxSum = Math.max(nums[i], nums[i] + maxSum);
max = Math.max(max, maxSum);
}
return max;
}
```