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
feat: add solutions to lc problems: No.1295,1299 (#3629)
* No.1295.Find Numbers with Even Number of Digits
* No.1297.Maximum Number of Occurrences of a Substring
* No.1299.Replace Elements with Greatest Element on Right Side
Copy file name to clipboardexpand all lines: solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md
+25-15
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ tags:
27
27
<pre>
28
28
<strong>Input:</strong> nums = [12,345,2,6,7896]
29
29
<strong>Output:</strong> 2
30
-
<strong>Explanation:
30
+
<strong>Explanation:
31
31
</strong>12 contains 2 digits (even number of digits).
32
32
345 contains 3 digits (odd number of digits).
33
33
2 contains 1 digit (odd number of digits).
@@ -40,7 +40,7 @@ Therefore only 12 and 7896 contain an even number of digits.
40
40
41
41
<pre>
42
42
<strong>Input:</strong> nums = [555,901,482,1771]
43
-
<strong>Output:</strong> 1
43
+
<strong>Output:</strong> 1
44
44
<strong>Explanation: </strong>
45
45
Only 1771 contains an even number of digits.
46
46
</pre>
@@ -59,7 +59,13 @@ Only 1771 contains an even number of digits.
59
59
60
60
<!-- solution:start -->
61
61
62
-
### Solution 1
62
+
### Solution 1: Simulation
63
+
64
+
We traverse each element $x$ in the array $\textit{nums}$. For the current element $x$, we directly convert it to a string and then check if its length is even. If it is, we increment the answer by one.
65
+
66
+
After the traversal is complete, we return the answer.
67
+
68
+
The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log M)$. Here, $n$ is the length of the array $\textit{nums}$, and $M$ is the maximum value of the elements in the array $\textit{nums}$.
63
69
64
70
<!-- tabs:start -->
65
71
@@ -68,7 +74,7 @@ Only 1771 contains an even number of digits.
Copy file name to clipboardexpand all lines: solution/1200-1299/1297.Maximum Number of Occurrences of a Substring/README_EN.md
+23-1
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,11 @@ It satisfies the conditions, 2 unique letters and size 3 (between minSize and ma
61
61
62
62
<!-- solution:start -->
63
63
64
-
### Solution 1
64
+
### Solution 1: Hash Table + Enumeration
65
+
66
+
According to the problem description, if a long string meets the condition, then its substring of length $\textit{minSize}$ must also meet the condition. Therefore, we only need to enumerate all substrings of length $\textit{minSize}$ in $s$, then use a hash table to record the occurrence frequency of all substrings, and find the maximum frequency as the answer.
67
+
68
+
The time complexity is $O(n \times m)$, and the space complexity is $O(n \times m)$. Here, $n$ and $m$ are the lengths of the string $s$ and $\textit{minSize}$, respectively. In this problem, $m$ does not exceed $26$.
0 commit comments