Skip to content

Commit f13fd31

Browse files
solves decompressrun length encoded list
1 parent f9302f7 commit f13fd31

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | |
338338
| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | |
339339
| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | |
340-
| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | |
340+
| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | |
341341
| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | |
342342
| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | |
343343
| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class DecompressRunLengthEncodedList {
2+
public int[] decompressRLElist(int[] nums) {
3+
final int totalElements = sumOfFrequency(nums);
4+
final int[] result = new int[totalElements];
5+
for (int i = 1, k = 0; i < nums.length ; i += 2) {
6+
for (int j = 0 ; j < nums[i - 1] ; j++) {
7+
result[k++] = nums[i];
8+
}
9+
}
10+
return result;
11+
}
12+
13+
private int sumOfFrequency(int[] array) {
14+
int sum = 0;
15+
for (int i = 0 ; i < array.length ; i += 2) {
16+
sum += array[i];
17+
}
18+
return sum;
19+
}
20+
}

0 commit comments

Comments
 (0)