We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2d0e0cc commit ba5d5e9Copy full SHA for ba5d5e9
javascript/0209-minimum-size-subarray-sum.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {number} target
3
+ * @param {number[]} nums
4
+ * @return {number}
5
+ */
6
+var minSubArrayLen = function (target, nums) {
7
+ let minLength = Infinity;
8
+ let leftWindow = 0;
9
+ let currentSum = 0;
10
+
11
+ for (let rightWindow = 0; rightWindow < nums.length; rightWindow++) {
12
+ currentSum += nums[rightWindow];
13
+ while (currentSum >= target) {
14
+ minLength = Math.min(minLength, rightWindow - leftWindow + 1);
15
+ currentSum -= nums[leftWindow];
16
+ leftWindow++;
17
+ }
18
19
+ return minLength === Infinity ? 0 : minLength;
20
+};
0 commit comments