教日月换新天。为有牺牲多壮志,敢

[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
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

热烈欢迎,请直接点击!!!

进入博主App Store主页,下载使用各个作品!!!

注:博主将坚持每月上线一个新app!!!

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 }
复制代码

 

posted @   为敢技术  阅读(400)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2019-01-13 [Swift]LeetCode975. 奇偶跳 | Odd Even Jump
2019-01-13 [Swift]LeetCode973. 最接近原点的 K 个点 | K Closest Points to Origin
2019-01-13 [Swift]LeetCode974. 和可被 K 整除的子数组 | Subarray Sums Divisible by K
2019-01-13 [Swift]LeetCode976. 三角形的最大周长 | Largest Perimeter Triangle
2019-01-13 [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String
2019-01-13 [Swift]LeetCode343. 整数拆分 | Integer Break
2019-01-13 [Swift]LeetCode338. 比特位计数 | Counting Bits
点击右上角即可分享
微信分享提示
西雅图
10:14发布
西雅图
10:14发布
4°
南风
3级
空气质量
相对湿度
94%
今天
小雨
3°/9°
周二
小雨
3°/9°
周三
中雨
5°/9°