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/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md
+7-1
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,13 @@ Note that even though the subarrays have the same content, the two subarrays are
48
48
49
49
## Solutions
50
50
51
-
### Solution 1
51
+
### Solution 1: Hash Table
52
+
53
+
We can traverse the array $nums$, and use a hash table $vis$ to record the sum of every two adjacent elements in the array. If the sum of the current two elements has already appeared in the hash table, then return `true`. Otherwise, add the sum of the current two elements to the hash table.
54
+
55
+
If we finish traversing and haven't found two subarrays that meet the condition, return `false`.
56
+
57
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the length of the array $nums$.
Copy file name to clipboardexpand all lines: solution/2300-2399/2398.Maximum Number of Robots Within Budget/README_EN.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,15 @@ It can be shown that it is not possible to run more than 3 consecutive robots wi
44
44
45
45
## Solutions
46
46
47
-
### Solution 1
47
+
### Solution 1: Two Pointers + Monotonic Queue
48
+
49
+
The problem is essentially finding the maximum value within a sliding window, which can be solved using a monotonic queue.
50
+
51
+
We only need to use binary search to enumerate the size of the window $k$, and find the largest $k$ that satisfies the problem requirements.
52
+
53
+
In the implementation process, we don't actually need to perform binary search enumeration. We just need to change the fixed window to a non-fixed window with double pointers.
54
+
55
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the number of robots in the problem.
Copy file name to clipboardexpand all lines: solution/2400-2499/2417.Closest Fair Integer/README_EN.md
+8-1
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,14 @@
39
39
40
40
## Solutions
41
41
42
-
### Solution 1
42
+
### Solution 1: Case Discussion
43
+
44
+
We denote the number of digits of $n$ as $k$, and the number of odd and even digits as $a$ and $b$ respectively.
45
+
46
+
- If $a = b$, then $n$ itself is `fair`, and we can directly return $n$;
47
+
- Otherwise, if $k$ is odd, we can find the smallest `fair` number with $k+1$ digits, in the form of `10000111`. If $k$ is even, we can directly brute force `closestFair(n+1)`.
48
+
49
+
The time complexity is $O(\sqrt{n} \times \log_{10} n)$.
Copy file name to clipboardexpand all lines: solution/2400-2499/2452.Words Within Two Edits of Dictionary/README_EN.md
+45-22
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,11 @@ Applying any two edits to "yes" cannot make it equal to "not"
47
47
48
48
## Solutions
49
49
50
-
### Solution 1
50
+
### Solution 1: Brute Force Enumeration
51
+
52
+
We directly traverse each word $s$ in the array $\text{queries}$, and then traverse each word $t$ in the array $\text{dictionary}$. If there exists a word $t$ whose edit distance from $s$ is less than $3$, we add $s$ to the answer array and then exit the inner loop. If there is no such word $t$, we continue to traverse the next word $s$.
53
+
54
+
The time complexity is $O(m \times n \times l)$, where $m$ and $n$ are the lengths of the arrays $\text{queries}$ and $\text{dictionary}$ respectively, and $l$ is the length of the word.
51
55
52
56
<!-- tabs:start -->
53
57
@@ -95,7 +99,9 @@ public:
95
99
for (auto& s : queries) {
96
100
for (auto& t : dictionary) {
97
101
int cnt = 0;
98
-
for (int i = 0; i < s.size(); ++i) cnt += s[i] != t[i];
0 commit comments