当前位置:首页 > Web开发 > 正文

【leetcode】1313. Decompress Run

2024-03-31 Web开发

We are given a list nums of integers representing a list compressed with run-length encoding.

Consider each adjacent pair of elements [a, b] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are a elements with value b in the decompressed list.

Return the decompressed list.

Example 1:

Input: nums = [1,2,3,4] Output: [2,4,4,4]

Constraints:

2 <= nums.length <= 100

nums.length % 2 == 0

1 <= nums[i] <= 100

解题思路:送分题。

代码如下:

class Solution(object): def decompressRLElist(self, nums): """ :type nums: List[int] :rtype: List[int] """ res = [] for i in range(0,len(nums)-1,2): res += [nums[i+1]] * nums[i] return res

【leetcode】1313. Decompress Run-Length Encoded List

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31717.html