From db3c36f3beeb9a6393580c7fcebc649849da0bc2 Mon Sep 17 00:00:00 2001 From: saurabh-172 <56040579+saurabh-172@users.noreply.github.com> Date: Mon, 19 Oct 2020 05:02:51 +0530 Subject: [PATCH] Create DecompressRunLengthEncodedList.py --- .../DecompressRunLengthEncodedList.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 leetcode/easy/Arrays and Strings/DecompressRunLengthEncodedList.py diff --git a/leetcode/easy/Arrays and Strings/DecompressRunLengthEncodedList.py b/leetcode/easy/Arrays and Strings/DecompressRunLengthEncodedList.py new file mode 100644 index 0000000..643c5f0 --- /dev/null +++ b/leetcode/easy/Arrays and Strings/DecompressRunLengthEncodedList.py @@ -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