Skip to content

Commit 3ff0de3

Browse files
authored
Create 0209-minimum-size-subarray-sum.kt
1 parent 64a7811 commit 3ff0de3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun minSubArrayLen(target: Int, nums: IntArray): Int {
3+
var windowSum = 0
4+
var left = 0
5+
var right = 0
6+
var res = Integer.MAX_VALUE
7+
8+
while (right < nums.size) {
9+
windowSum += nums[right++]
10+
while (left < nums.size && windowSum >= target) {
11+
res = minOf(res, right - left)
12+
windowSum -= nums[left++]
13+
}
14+
}
15+
16+
return if (res == Integer.MAX_VALUE) 0 else res
17+
}
18+
}

0 commit comments

Comments
 (0)