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;
    }
}

 

上一篇:Java-通过SurfaceView使用Zxing条形码阅读器


下一篇:LintCode 41---最大子数组