I use Kadane algorigthm, more details in my blog,

blog click here

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