其他分享
首页 > 其他分享> > LintCode 44---最小子数组

LintCode 44---最小子数组

作者:互联网

public class Solution {
    /*
     * @param nums: a list of integers
     * @return: A integer indicate the sum of minimum subarray
     */
    public int minSubArray(List<Integer> nums) {
        // write your code here
         if (nums == null)
        return 0;
    int minSum = Integer.MAX_VALUE;
    int maxSum = 0;
    int sum = 0;
    
    for (Integer num: nums) {
        sum += num;
        minSum = Math.min(minSum, sum - maxSum);
        maxSum = Math.max(maxSum, sum);
    }
    
    return minSum;
    }
}

 

标签:return,nums,int,44,LintCode,maxSum,minSum,数组,sum
来源: https://www.cnblogs.com/cnmoti/p/10828346.html