在线时间:8:00-16:00
迪恩网络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] Constraints: 2 <= nums.length <= 100 给你一个以行程长度编码压缩的整数列表 nums 。 考虑每相邻两个元素 [a, b] = [nums[2*i], nums[2*i+1]] (其中 i >= 0 ),每一对都表示解压后有 a 个值为 b 的元素。 请你返回解压后的列表。
示例: 输入:nums = [1,2,3,4] 提示: 2 <= nums.length <= 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 }
|
请发表评论