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 5c6288d

Browse files
Add solution to 209.
1 parent c923409 commit 5c6288d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @param {number} target
3+
* @param {number[]} nums
4+
* @return {number}
5+
*/
6+
var minSubArrayLen = function (target, nums) {
7+
if (nums.length === 0) {
8+
return 0;
9+
}
10+
11+
let s = 0;
12+
let ok = false;
13+
let length = nums.length;
14+
let i = 0,
15+
j = 0;
16+
17+
while (j < nums.length) {
18+
s += nums[j];
19+
20+
if (s >= target) {
21+
ok = true;
22+
length = Math.min(j - i + 1, length);
23+
24+
s -= nums[i];
25+
i++;
26+
while (s >= target) {
27+
length = Math.min(j - i + 1, length);
28+
s -= nums[i];
29+
i++;
30+
}
31+
}
32+
33+
j++;
34+
}
35+
36+
return ok ? length : 0;
37+
};

0 commit comments

Comments
(0)

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