Skip to content

Commit 510c918

Browse files
committed
Add solution #1588
1 parent d5ed79f commit 510c918

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,386 LeetCode solutions in JavaScript
1+
# 1,387 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1211,6 +1211,7 @@
12111211
1583|[Count Unhappy Friends](./solutions/1583-count-unhappy-friends.js)|Medium|
12121212
1584|[Min Cost to Connect All Points](./solutions/1584-min-cost-to-connect-all-points.js)|Medium|
12131213
1585|[Check If String Is Transformable With Substring Sort Operations](./solutions/1585-check-if-string-is-transformable-with-substring-sort-operations.js)|Hard|
1214+
1588|[Sum of All Odd Length Subarrays](./solutions/1588-sum-of-all-odd-length-subarrays.js)|Easy|
12141215
1598|[Crawler Log Folder](./solutions/1598-crawler-log-folder.js)|Easy|
12151216
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12161217
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1588. Sum of All Odd Length Subarrays
3+
* https://leetcode.com/problems/sum-of-all-odd-length-subarrays/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of positive integers arr, return the sum of all possible odd-length
7+
* subarrays of arr.
8+
*
9+
* A subarray is a contiguous subsequence of the array.
10+
*/
11+
12+
/**
13+
* @param {number[]} arr
14+
* @return {number}
15+
*/
16+
var sumOddLengthSubarrays = function(arr) {
17+
let result = 0;
18+
19+
for (let index = 0; index < arr.length; index++) {
20+
result += arr[index] * Math.ceil(((index + 1) * (arr.length - index)) / 2);
21+
}
22+
23+
return result;
24+
};

0 commit comments

Comments
 (0)