Skip to content

Commit 2a73b35

Browse files
authored
Create decompress-run-length-encoded-list.cpp
1 parent 87c3ecf commit 2a73b35

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<int> decompressRLElist(vector<int>& nums) {
7+
vector<int> result;
8+
for (int i = 0; i < nums.size(); i += 2) {
9+
for (int j = 0; j < nums[i]; ++j) {
10+
result.emplace_back(nums[i + 1]);
11+
}
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)