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