You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/1300-1399/1313.Decompress Run-Length Encoded List/README_EN.md
+41-39
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,11 @@ At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
57
57
58
58
<!-- solution:start -->
59
59
60
-
### Solution 1
60
+
### Solution 1: Simulation
61
+
62
+
We can directly simulate the process described in the problem. Traverse the array $\textit{nums}$ from left to right, each time taking out two numbers $\textit{freq}$ and $\textit{val}$, then repeat $\textit{val}$ $\textit{freq}$ times, and add these $\textit{freq}$ $\textit{val}$s to the answer array.
63
+
64
+
The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. We only need to traverse the array $\textit{nums}$ once. Ignoring the space consumption of the answer array, the space complexity is $O(1)$.
61
65
62
66
<!-- tabs:start -->
63
67
@@ -66,28 +70,21 @@ At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
0 commit comments