文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
int index = 0;
int minimum = INT_MAX;
for(int i = 0; i < nums.size(); i++) {
s = s - nums[i];
while(s <= 0) {
minimum = min(minimum, i - index + 1);
s += nums[index++];
}
}
if(minimum == INT_MAX) {
return 0;
}
return minimum;
}
};