Skip to content

Commit 15b6226

Browse files
committedJan 20, 2020
Add solution #1313
1 parent c5585d7 commit 15b6226

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 1313. Decompress Run-Length Encoded List
3+
* https://leetcode.com/problems/decompress-run-length-encoded-list/
4+
* Difficulty: Easy
5+
*
6+
* We are given a list nums of integers representing a list compressed with run-length encoding.
7+
*
8+
* Consider each adjacent pair of elements [a, b] = [nums[2*i], nums[2*i+1]] (with i >= 0).
9+
* For each such pair, there are a elements with value b in the decompressed list.
10+
*
11+
* Return the decompressed list.
12+
*/
13+
14+
/**
15+
* @param {number[]} nums
16+
* @return {number[]}
17+
*/
18+
var decompressRLElist = function(nums, result = []) {
19+
for (let i = 0; i < nums.length; i += 2) {
20+
result.push(...new Array(nums[i]).fill(nums[i + 1]));
21+
}
22+
return result;
23+
};

0 commit comments

Comments
 (0)
Please sign in to comment.