Skip to content

Commit 64cf0cf

Browse files
committed
add 0209 Solution for Java
1 parent c44916c commit 64cf0cf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int minSubArrayLen(int s, int[] nums) {
3+
int n = nums.length;
4+
int ans = Integer.MAX_VALUE;
5+
int start = 0, end = 0;
6+
int sum = 0;
7+
while (start < n) {
8+
while (end < n && sum < s) {
9+
sum += nums[end];
10+
end++;
11+
}
12+
if (sum >= s) {
13+
ans = Math.min(ans, end - start);
14+
}
15+
sum -= nums[start];
16+
start++;
17+
}
18+
return ans == Integer.MAX_VALUE ? 0 : ans;
19+
}
20+
}

0 commit comments

Comments
 (0)