Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create DecompressRunLengthEncodedList.py #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions leetcode/easy/Arrays and Strings/DecompressRunLengthEncodedList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''We are given a list nums of integers representing a list compressed with run-length encoding.
Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).
For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate
all the sublists from left to right to generate the decompressed list.
Return the decompressed list.
'''

class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
arr = []
for i in range(0, len(nums), 2):
for j in range(nums[i]):
arr.append(nums[i+1])
return arr