力扣209. 长度最小的子字符串
代码
class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int result = INT32_MAX;
int sum = 0;
int i = 0;
int length = 0;
for(int j = 0;j<nums.size();j++){
sum += nums[j];
while(sum>=target){
length = j-i+1;
result = min(result,length);
sum = sum - nums[i];
i++;
}
}
return result == INT32_MAX ? 0 : result; 如果result没有被赋值的话,就返回0,说明没有符合条件的子序列
}
};