209. Minimum Size Subarray Sum

Posted gopanama

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了209. Minimum Size Subarray Sum相关的知识,希望对你有一定的参考价值。

 1 class Solution {
 2     public int minSubArrayLen(int s, int[] nums) {
 3         if(nums.length == 0) return 0;
 4         int count = 0;
 5         int i = 0, j = 0;
 6         int min = Integer.MAX_VALUE;
 7         while(j < nums.length){
 8             count += nums[j++];
 9             while(count > s){
10                 min = Math.min(min, j - i);
11                 count -= nums[i++];
12             }
13             if(count == s){
14                 min = Math.min(min, j - i);
15             }
16         }
17         if(min == Integer.MAX_VALUE){
18             return 0;
19         }else{
20             return min;
21         }
22         
23         
24     }
25 }

 

以上是关于209. Minimum Size Subarray Sum的主要内容,如果未能解决你的问题,请参考以下文章

209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum