forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_209.java
More file actions
25 lines (22 loc) · 651 Bytes
/
_209.java
File metadata and controls
25 lines (22 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions;
public class _209 {
public static class Solution1 {
public int minSubArrayLen(int s, int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int i = 0;
int j = 0;
int min = Integer.MAX_VALUE;
int sum = 0;
while (j < nums.length) {
sum += nums[j++];
while (sum >= s) {
min = Math.min(min, j - i);
sum -= nums[i++];
}
}
return min == Integer.MAX_VALUE ? 0 : min;
}
}
}