赞
踩
https://leetcode.cn/problems/minimum-size-subarray-sum/description
class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int result = INT32_MAX;
int sum = 0;
int length = 0;
int i = 0;
for(int j = 0; j < nums.size(); j++){
sum += nums[j];
while(sum >= target){
length = j - i + 1;
result = result < length ? result : length;
sum -= nums[i++];
}
}
return result == INT32_MAX ? 0 : result;
}
};
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。