Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a7763d

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /