Decompress Run-Length Encoded List LeetCode solution in Java

1
class Solution {
2
public int[] decompressRLElist(int[] nums) {
3
ArrayList<Integer> arr = new ArrayList<>();
4
for (int i = 0; i + 1 < nums.length; i += 2) {
5
for (int j = 0; j < nums[i]; ++j) {
6
arr.add(nums[i + 1]);
7
}
8
}
9
int[] res = new int[arr.size()];
10
for (int i = 0; i < res.length; ++i) res[i] = arr.get(i);
11
return res;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0