```
public int minSubArrayLen(int s, int[] nums) {
int i = 0, j = 0, sum = 0, n = nums.length, result = n + 1;
while (j < n) {
while (j < n && sum < s) sum += nums[j++];
if (j == n && sum < s) break;
while (sum >= s) {
result = Math.min(result, j - i);
sum -= nums[i++];
}
}
return result > n ? 0 : result;
}
```