public class Solution { /** * @param nums: A list of integers * @return: A integer indicate the sum of max subarray */ public int maxSubArray(int[] nums) { int n = nums.length; int ans = -1000000; int sum = 0; for(int i=0; ians) { ans = sum; } if(sum < 0) { sum = 0; //子串和为负数,丢掉 } } return ans; }}