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/2800-2899/2899.Last Visited Integers/README_EN.md
+97-3
Original file line number
Diff line number
Diff line change
@@ -48,30 +48,124 @@ For "prev" at index = 4, last visited integer will be 1 as there are a
48
48
49
49
## Solutions
50
50
51
+
**Solution 1: Simulation**
52
+
53
+
We can directly simulate according to the problem statement. In the implementation, we use an array $nums$ to store the traversed integers, and an integer $k$ to record the current number of consecutive $prev$ strings. If the current string is $prev$, we take out the $|nums| - k-th$ integer from $nums$. If it does not exist, we return $-1$.
54
+
55
+
The time complexity is $O(n)$, where $n$ is the length of the array $words$. The space complexity is $O(n)$.
0 commit comments