zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1313. 解压缩编码列表 | Decompress Run-Length Encoded List

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/12185566.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    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


     给你一个以行程长度编码压缩的整数列表 nums 。

    考虑每相邻两个元素 [a, b] = [nums[2*i], nums[2*i+1]] (其中 i >= 0 ),每一对都表示解压后有 a 个值为 b 的元素。

    请你返回解压后的列表。

    示例:

    输入:nums = [1,2,3,4]
    输出:[2,4,4,4]
     

    提示:

    2 <= nums.length <= 100
    nums.length % 2 == 0
    1 <= nums[i] <= 100


    Runtime: 60 ms
    Memory Usage: 21.2 MB
     1 class Solution {
     2     func decompressRLElist(_ nums: [Int]) -> [Int] {
     3         var res:[Int] = [Int]()
     4         for i in stride(from:0,to:nums.count,by:2)
     5         {
     6             for j in 0..<nums[i]
     7             {
     8                 res.append(nums[i + 1])
     9             }
    10         }
    11         return res
    12     }
    13 }
  • 相关阅读:
    完美解决Python与anaconda之间的冲突问题
    ansible之roles
    ansible剧本之playbook操作
    git从远程仓库拉取内容或向远程仓库上传内容
    python操作excel
    nginx基于uwsgi部署Django
    第二篇:版本控制git之分支
    笔试题92-101
    Django总结
    笔试题70-91
  • 原文地址:https://www.cnblogs.com/strengthen/p/12185566.html
Copyright © 2011-2022 走看看