Use two pointer to find the minimum subarray size;

At first, we find the shortest subarray from the first element of which the sum is greater than or equal to target. We set tailIdx to be the index of the last element of that subarray. 

Then move the headIdx to find the possible shortest subarray which the last element is in the tailIdx position. Now we move the headIdx and tailIdx concurrently by adding one to get the next subarray which has the sum is greater than or equal to target. Then we go to the step 1.

After the step 1 and in the procedure of step 2 the tailIdx get to end of the array, return the count. Or we get to an element of which the value is greater than or equal to the target, return 1.

 

posted on 2016-02-23 04:58  爱推理的骑士  阅读(137)  评论(0编辑  收藏  举报