class Solution { public: int minSubArrayLen(int target, vector<int>& nums) { int maxsize = INT_MAX; int left = 0; int right = 0; int sum = 0; while(right<nums.size()){ sum = sum + nums[right]; cout<<"right: "<<right<<" sum: "<<sum<<endl; // 为什么搞个while循环 // 因为如果现在区间内的元素和大于targettarget,移除最坐标元素以后, // 可能此时和等于target while(sum>=target){ maxsize = min(maxsize, right-left+1); sum = sum - nums[left]; left++; // 区间左移 } right++; } return maxsize = maxsize==INT_MAX?0:maxsize; } };