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 08d8c6b commit 66507c6Copy full SHA for 66507c6
Sliding-Windows/Sum of Odd length Subarrays
@@ -0,0 +1,23 @@
1
+
2
+/**
3
+ * @param {number[]} nums
4
+ * @param {number} k
5
+ * @return {void} Do not return anything, modify nums in-place instead.
6
+ */
7
+var sumOddLengthSubarrays = function (arr) {
8
+ let oddsum = 0;
9
10
+ for (let i = 0; i < arr.length; i++) {
11
+ let prevsum = 0;
12
+ for (let j = i; j < arr.length; j++) {
13
+ prevsum = prevsum + arr[j];
14
15
+ let length = j-i + 1;
16
17
+ if (length % 2 === 1) {
18
+ oddsum = oddsum + prevsum;
19
+ }
20
21
22
+ return oddsum;
23
+}
0 commit comments