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/2200-2299/2293.Min Max Game/README_EN.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,11 @@ Third: nums = [1]
69
69
70
70
<!-- solution:start -->
71
71
72
-
### Solution 1
72
+
### Solution 1: Simulation
73
+
74
+
According to the problem statement, we can simulate the entire process, and the remaining number will be the answer. In implementation, we do not need to create an additional array; we can directly operate on the original array.
75
+
76
+
The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. The space complexity is $O(1)$.
Copy file name to clipboardexpand all lines: solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,11 @@ Since three subsequences were created, we return 3. It can be shown that 3 is th
79
79
80
80
<!-- solution:start -->
81
81
82
-
### Solution 1
82
+
### Solution 1: Greedy + Sorting
83
+
84
+
The problem requires dividing into subsequences, not subarrays, so the elements in a subsequence can be non-continuous. We can sort the array $\textit{nums}$. Assuming the first element of the current subsequence is $a$, the difference between the maximum and minimum values in the subsequence will not exceed $k$. Therefore, we can iterate through the array $\textit{nums}$. If the difference between the current element $b$ and $a$ is greater than $k$, then update $a$ to $b$ and increase the number of subsequences by 1. After the iteration, we can obtain the minimum number of subsequences, noting that the initial number of subsequences is $1$.
85
+
86
+
The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log n)$. Here, $n$ is the length of the array $\textit{nums}$.
Copy file name to clipboardexpand all lines: solution/2200-2299/2295.Replace Elements in an Array/README_EN.md
+25-24
Original file line number
Diff line number
Diff line change
@@ -78,11 +78,11 @@ We return the array [2,1].
78
78
79
79
### Solution 1: Hash Table
80
80
81
-
First, we use a hash table $d$ to record the index of each number in the array `nums`. Then, we iterate through the operation array `operations`. For each operation $[a, b]$, we replace the number at index $d[a]$ in `nums` with $b$, and update the index of $b$ in $d$ to $d[a]$.
81
+
First, we use a hash table $d$ to record the indices of each number in the array $\textit{nums}$. Then, we iterate through the operation array $\textit{operations}$. For each operation $[x, y]$, we replace the number at index $d[x]$ in $\textit{nums}$ with $y$, and update the index of $y$ in $d$ to $d[x]$.
82
82
83
-
Finally, we return `nums`.
83
+
Finally, we return $\textit{nums}$.
84
84
85
-
The time complexity is $O(n + m)$, and the space complexity is $O(n)$. Here, $n$ and $m$ are the lengths of the arrays `nums` and `operations`, respectively.
85
+
The time complexity is $O(n + m)$, and the space complexity is $O(n)$. Here, $n$ and $m$ are the lengths of the array $\textit{nums}$ and the operation array $\textit{operations}$, respectively.
86
86
87
87
<!-- tabs:start -->
88
88
@@ -91,10 +91,10 @@ The time complexity is $O(n + m)$, and the space complexity is $O(n)$. Here, $n$
0 commit comments