1. What I learned
Create a list with a repeated number when I know the length of a list
Write a number in a []. Multiply it by the length of the list.
ex) numList = [5]*3
–> numList = [5,5,5]
2. How I sloved
I made a list and repeated ‘nums//2’ to make the final list. Because the list had a pattern that odd numbers were the frequency of even numbers. Then I concatenated the even numbers to the ‘result’ list as many odd numbers.
3. Code
class Solution:
def decompressRLElist(self, nums):
result = []
for i in range(0,len(nums)//2):
result += [nums[2*i+1]] * nums[2*i]
return result
4. Result
Runtime : 64 ms(87.63%), Memory usage : 13.3 MB(100.00%)
(Runtime can be different by a system even if it is a same code.)