class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int n = nums.size();
if(n == 0) return 0;
int res = 2e9;
int st = 0,ed = 0;
int sum = 0;
while(ed < n){
sum += nums[ed++];
while(sum >= target){
res = min(res,ed-st);
sum -= nums[st++];
}
}
return res==2e9 ? 0 : res;
}
};