{"id":6074,"date":"2020-01-11T10:31:40","date_gmt":"2020-01-11T18:31:40","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=6074"},"modified":"2020-01-11T10:32:33","modified_gmt":"2020-01-11T18:32:33","slug":"leetcode-1313-decompress-run-length-encoded-list","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/simulation\/leetcode-1313-decompress-run-length-encoded-list\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1313. Decompress Run-Length Encoded List"},"content":{"rendered":"\n<p>We are given a list&nbsp;<code>nums<\/code>&nbsp;of integers representing a list compressed with run-length encoding.<\/p>\n\n\n\n<p>Consider each adjacent pair&nbsp;of elements&nbsp;<code>[a, b] = [nums[2*i], nums[2*i+1]]<\/code>&nbsp;(with&nbsp;<code>i &gt;= 0<\/code>).&nbsp; For each such pair, there are&nbsp;<code>a<\/code>&nbsp;elements with value&nbsp;<code>b<\/code>&nbsp;in the decompressed list.<\/p>\n\n\n\n<p>Return the decompressed list.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> nums = [1,2,3,4]\n<strong>Output:<\/strong> [2,4,4,4]\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>2 &lt;= nums.length &lt;= 100<\/code><\/li><li><code>nums.length % 2 == 0<\/code><\/li><li><code>1 &lt;= nums[i] &lt;= 100<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Simulation<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(sum(n_i))<br>Space complexity: O(sum(n_i)) or O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"C++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  vector<int> decompressRLElist(vector<int>& nums) {\n    vector<int> ans;\n    for (int i = 0; i < nums.size(); i += 2)\n      for (int j = 0; j < nums[i]; ++j)\n        ans.push_back(nums[i + 1]);\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We are given a list&nbsp;nums&nbsp;of integers representing a list compressed with run-length encoding. Consider each adjacent pair&nbsp;of elements&nbsp;[a, b] = [nums[2*i], nums[2*i+1]]&nbsp;(with&nbsp;i &gt;= 0).&nbsp; For&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[222,271,179],"class_list":["post-6074","post","type-post","status-publish","format-standard","hentry","category-simulation","tag-easy","tag-run-length","tag-simulation","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=6074"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6074\/revisions"}],"predecessor-version":[{"id":6076,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6074\/revisions\/6076"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=6074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=6074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=6074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}