/*
* @lc app=leetcode id=209 lang=cpp
*
* [209] Minimum Size Subarray Sum
*/
// @lc code=start
class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
int N = nums.size();
if(N<=0) return 0;
int ans = N;
int L = 0;
int R = 0;
int sum = 0;
bool flag = false;
while(R<N){
sum += nums[R++];
while(sum >= s){
flag = true;
ans = min(ans,R-L);
sum -= nums[L++];
}
}
return flag?ans:0;
}
};
// @lc code=end