public int maxSubArray(int[] nums) {
if(nums.length==1)
return nums[0];
int preSum = nums[0];
int max = nums[0];
for(int i=1; i<nums.length; i++){
if(preSum<=0)
preSum=nums[i];
else{
preSum+=nums[i];
}
if(preSum>max)
max = preSum;
}
return max;
}
1ms JAVA O(N) solution, no dp

It is DP, see the transformation made in https://leetcode.com/discuss/65791/8mscdpsolution