EasyNo. 1313
Decompress Run-Length Encoded List — LeetCode 1313 Python Solution
- Topics
- Array
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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).
Example
- 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].
Python solution
class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
return [nums[i + 1] for i in range(0, len(nums), 2) for _ in range(nums[i])]Complexity
- Time
- O(n)where n is the length of the array nums
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0228 | Summary Ranges | Easy |
| 0485 | Max Consecutive Ones | Easy |
| 0665 | Non-decreasing Array | Medium |
| 0674 | Longest Continuous Increasing Subsequence | Easy |
| 0699 | Falling Squares | Hard |
Frequently asked questions
- How hard is LeetCode 1313. Decompress Run-Length Encoded List?
LeetCode 1313. Decompress Run-Length Encoded List is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1313. Decompress Run-Length Encoded List?
The Python solution on this page runs in O(n), where n is the length of the array \textit{nums}.
- What is the space complexity of LeetCode 1313. Decompress Run-Length Encoded List?
The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 1313. Decompress Run-Length Encoded List cover?
LeetCode 1313. Decompress Run-Length Encoded List is tagged Array on LeetCode.