Skip to content

Commit 0dd9c56

Browse files
authored
Merge pull request neetcode-gh#2428 from IliaEre/0209-minimum-size-subarray-sum
Create: 209 Minimum Size Subarray Sum
2 parents c45c85a + b6001ef commit 0dd9c56

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
3+
public int minSubArrayLen(int target, int[] nums) {
4+
int l = 0, total = 0;
5+
int res = Integer.MAX_VALUE;
6+
7+
for (int r = 0; r < nums.length; r++) {
8+
total += nums[r];
9+
while (total >= target) {
10+
res = Math.min(r - l + 1, res);
11+
total -= nums[l++];
12+
}
13+
}
14+
15+
return res == Integer.MAX_VALUE ? 0 : res;
16+
}
17+
}

0 commit comments

Comments
 (0)