class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
int len = nums.size();
if (len == 0) return 0;
int min = INT_MAX;
int sum = 0;
int left = 0, right = -1;
while(right < len) {
while(sum < s && right < len) {
sum += nums[++right];
}
if (sum >= s) {
min = min < right - left + 1 ? min : right - left + 1;
sum -= nums[left++];
}
}
return min > len ? 0 : min;
}
};