209. Minimum Size Subarray Sum

class Solution {
    public int minSubArrayLen(int s, int[] nums) {
        int i=0;
        int j=0;
        int len= Integer.MAX_VALUE;
        int sum=0;
        while(j<=nums.length)
        {
            if(sum<s&&j<nums.length)
            {
                sum+=nums[j];
                j++;
            }
            else if(sum>=s)
            {
                len=Math.min(len, j-i);
                System.out.println(j-i);
                sum-=nums[i];
                i++;
            }
            else
                break;
        }
        return len==Integer.MAX_VALUE?0:len;
    }
}

  

转载于:https://www.cnblogs.com/asuran/p/7797152.html

上一篇:209. 长度最小的子数组


下一篇:【转】Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat