Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1a7763d

Browse files
authored
Create 209. Minimum Size Subarray Sum
1 parent cd52399 commit 1a7763d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

209. Minimum Size Subarray Sum

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

0 commit comments

Comments
 (0)