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/2269.Find the K-Beauty of a Number/README_EN.md
+125-1
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,11 @@ Therefore, the k-beauty is 2.
60
60
61
61
## Solutions
62
62
63
-
### Solution 1
63
+
### Solution 1: Enumeration
64
+
65
+
We can convert $num$ to a string $s$, then enumerate all substrings of $s$ with length $k$, convert them to an integer $t$, and check if $t$ is divisible by $num$. If it is, we increment the answer.
66
+
67
+
The time complexity is $O(\log num \times k)$, and the space complexity is $O(\log num + k)$.
64
68
65
69
<!-- tabs:start -->
66
70
@@ -137,4 +141,124 @@ function divisorSubstrings(num: number, k: number): number {
137
141
138
142
<!-- tabs:end -->
139
143
144
+
### Solution 2: Sliding Window
145
+
146
+
We can maintain a sliding window of length $k$. Initially, the window contains the lowest $k$ digits of $num$. Then, for each iteration, we move the window one digit to the right, update the number in the window, and check if the number in the window is divisible by $num$. If it is, we increment the answer.
147
+
148
+
The time complexity is $O(\log num)$, and the space complexity is $O(1)$.
0 commit comments