Minimum Size Subarray Sum; Two Pointer;

本文介绍了一种使用两指针法寻找满足条件的最短子数组的方法。首先找到从首个元素开始的最短子数组,其和大于等于目标值。随后移动头部指针来寻找可能的更短子数组,直至尾部指针到达数组末尾。

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.

 

转载于:https://www.cnblogs.com/5683yue/p/5208671.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值