```
public class Solution {
public int maxSubArray(int[] nums) {
if(nums==null || nums.length==0){
return 0;
}
int max=Integer.MIN_VALUE;
int sum=0,i=0;
while(i<nums.length){
sum+=nums[i];
if(sum>max){
max=sum;
}
if(sum<=0){
sum=0;
}
i++;
}
return max;
}
}
```