[LeetCode]#1313. Decompress Run-Length Encoded List

Input: nums = [1,2,3,4]
Output: [2,4,4,4]
Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].
The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].
At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
Input: nums = [1,1,2,3]
Output: [1,3,3]
  • 2 <= nums.length <= 100
  • nums.length % 2 == 0
  • 1 <= nums[i] <= 100
class Solution:
def decompressRLElist(self, nums):
ans=[]
l=len(nums)
for i in range(0,l,2):
ans.extend(nums[i]*[nums[i+1]])
return ans

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Weekly update from PointPay (4 April–8 April 2022)

Create a DocuSign Integration for RingCentral

Why We Adopted An SRE Approach

10 reasons to dump your no-code platform

Container, which stores environments of computer

Pre-Coding Ritual

How to set up NDK in Android Studio ?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

How to implement a Queue class using deque. PYTHON data structures and algorithm.

[LeetCode]#2057. Smallest Index With Equal Value

LeetCode Patterns Adventure 29 — Invert Binary Tree

Implementing Linked Lists in Python