# 解壓縮遊程長度編碼列表Leetcode解決方案

`nums = [1,2,3,4]`
`[2,4,4,4]`

`nums = [1,1,2,3]`
`[1,3,3]`

## 解壓縮運行長度編碼列表Leetcode解決方案的代碼

### C ++代碼

```#include <bits/stdc++.h>
using namespace std;

vector<int> decompressRLElist(vector<int>& nums) {
vector<int> tmp;
for(int i=0;i<nums.size();i+=2){
for(int j=0;j<nums[i];j++)
tmp.push_back(nums[i+1]);
}
return tmp;
}

int main(){
vector<int> input = {1,2,3,4};
vector<int> output = decompressRLElist(input);
for(auto x: output)cout<<x<<" ";
}
```
`2 4 4 4`

### Java代碼

```import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
public static int[] decompressRLElist(int[] nums) {
int size = 0, k = 0;
for(int i=0;i<nums.length;i+=2)
size += nums[i];
int[] tmp = new int[size];
for(int i=0;i<nums.length;i+=2){
for(int j=0;j<nums[i];j++)
tmp[k++] = nums[i+1];
}
return tmp;
}

public static void main (String[] args) throws java.lang.Exception{
int[] input = {1,2,3,4};
int[] output = decompressRLElist(input);
for(Integer x: output)System.out.print(x+" ");
}
}```
`2 4 4 4`