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

  

posted @ 2017-11-07 04:17  Weiyu Wang  阅读(85)  评论(0编辑  收藏  举报