Skip to content

Commit f55f979

Browse files
committed
Time: 1 ms (99.98%), Space: 41.9 MB (9.31%) - LeetHub
1 parent 5564e55 commit f55f979

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+
public int minSubArrayLen(int target, int[] nums) {
3+
4+
int minLength = Integer.MAX_VALUE;
5+
int left = 0;
6+
int sum = 0;
7+
for(int right = 0;right < nums.length;right++){
8+
sum += nums[right];
9+
while(sum >= target){
10+
minLength = Math.min( minLength, (right - left) + 1 );
11+
sum -= nums[left++];
12+
}
13+
}
14+
15+
return minLength == Integer.MAX_VALUE ? 0 : minLength;
16+
}
17+
}

0 commit comments

Comments
 (0)