public int maxSubArray(int[] nums) {

```
int length = nums.length;
int max = Integer.MIN_VALUE;
int minsum = 0;
int sum = 0;
for(int i=0;i<length;i++){
sum+=nums[i];
max = Math.max(max,sum-minsum);
minsum = Math.min(sum,minsum);
}
return max;
}
```