运用队列的思维,求出每种满足题意的子数组长度,最小的即为答案,否则返回0
code
class Solution {public int minSubArrayLen(int target, int[] nums) {int l=0,r=0;int ans=Integer.MAX_VALUE;int total=0;while(r<nums.length){total+=nums[r++];if(total>=target){while(total-nums[l]>=target){total=total-nums[l++];}ans=Math.min(ans,r-l);}}if(ans==Integer.MAX_VALUE) return 0;return ans;}
}