Decompress Run-Length Encoded List
给一个数组, 里面是一对对的数, 偶数位的数字表示频率, 奇数位的数字表示前一个偶数位的值. 求原始数组.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class Solution { public int[] decompressRLElist(int[] nums) { List<Integer> list = new ArrayList<>(); for(int i = 0; i < nums.length; i+=2) { for(int j = 0; j < nums[i]; j++) { list.add(nums[i+1]); } } int[] res = new int[list.size()]; for(int i = 0; i < res.length; i++) { res[i] = list.get(i); } return res; } } |