class Solution {
public int minSubArrayLen(int s, int[] nums) {
int n = nums.length;
if (n <= 0) return 0;
int start = 0, end = 0, sum = 0;
int ans = Integer.MAX_VALUE;
while (end < n){
sum += nums[end];
while (sum >= s){
ans = Math.min(end - start + 1, ans);
sum -= nums[start];
start ++;
}
end ++;
}
return ans == Integer.MAX_VALUE ? 0 : ans;
}
}