Here is my solution below. Somehow it times out but I don't know why. Any idea?

```
public class Solution {
public int minSubArrayLen(int s, int[] nums) {
int ans = Integer.MAX_VALUE;
int sum = 0;
int left = 0;
for (int i = 0; i < nums.length; i++)
sum += nums[i];
while (sum >= s)
ans = Math.min(ans, i - left + 1);
sum -= nums[left++];
if (ans == Integer.MAX_VALUE) return 0;
else return ans;
}
}
```