We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cbebd68 commit 60e51a8Copy full SHA for 60e51a8
209-minimum-size-subarray-sum.js
@@ -0,0 +1,25 @@
1
+// problem link https://leetcode.com/problems/minimum-size-subarray-sum/submissions/612844825/
2
+// time complexity is O(n).
3
+
4
+var minSubArrayLen = function(target, nums) {
5
6
+ let total = 0;
7
+ let min_length = Number.MAX_SAFE_INTEGER;
8
+ let left_pointer = 0;
9
+ for(let i = 0; i < nums.length; i++) {
10
11
+ total += nums[i];
12
+ while(total >= target) {
13
+ min_length = Math.min(min_length, i + 1 - left_pointer);
14
+ total -= nums[left_pointer];
15
+ left_pointer = left_pointer+1;
16
+ }
17
18
19
+ if(min_length == Number.MAX_SAFE_INTEGER) {
20
+ return 0;
21
+ } else {
22
+ return min_length;
23
24
+};
25
0 commit comments