class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
queue<int> Q;
int sum=0;
int ans=nums.size()+1;
for(auto num:nums){
sum+=num;
Q.push(num);
while(sum>=target){
ans=min(ans,(int)Q.size());
int front=Q.front();
Q.pop();
sum-=front;
}
}
if(ans==(nums.size()+1)){
return 0;
}
else{
return ans;
}
}
};
209. 长度最小的子数组
最新推荐文章于 2023-02-01 19:58:18 发布