码迷,mamicode.com
首页 > Web开发 > 详细

【leetcode】1313. Decompress Run-Length Encoded List

时间:2020-01-12 18:18:25      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:with   each   class   col   +=   ide   block   nbsp   present   

题目如下:

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

标签:with   each   class   col   +=   ide   block   nbsp   present   

原文地址:https://www.cnblogs.com/seyjs/p/12183167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!