-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy path1313.java
More file actions
30 lines (26 loc) · 766 Bytes
/
1313.java
File metadata and controls
30 lines (26 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* for java 8
class Solution {
public int[] decompressRLElist(int[] nums) {
List<Integer> res = new ArrayList();
for (int i = 0; i < nums.length; i += 2)
for (int j = 0; j < nums[i]; ++j)
res.add(nums[i + 1]);
return res.stream().mapToInt(i -> i).toArray();
}
}
*/
class Solution {
public int[] decompressRLElist(int[] nums) {
int len = 0;
for(int i = 0; i < nums.length; i += 2) {
len += nums[i];
}
int[] res = new int[len];
int cur = 0;
for (int i = 1; i < nums.length; i += 2) {
Arrays.fill(res, cur, cur + nums[i - 1], nums[i]);
cur += nums[i - 1];
}
return res;
}
}