```
public class Solution {
public int minSubArrayLen(int s, int[] nums) {
int count = 0;
int minCount = 0;
int index = 0;
int startIndex = 0;
int sum = 0;
while (index<nums.length){
sum = sum + nums[index]; //keep adding until sum >= s
index++;
count++;
if (sum>=s){
if (count<minCount || minCount == 0){
minCount = count;
}
while (sum>s){//keep removing until sum<=s
sum = sum - nums[startIndex];
startIndex++;
count--;
if (sum>=s && count<minCount){ //if sum is still greater reduce count
minCount=count;
}
}
}
}
return minCount;
}
}
```