File tree 1 file changed +12
-11
lines changed
scripts/algorithms/F/Find the K-Beauty of a Number
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 0 ms (Top 100.00%) | Memory: 6 MB (Top 61.38%)
1
2
class Solution {
2
3
public:
3
4
int divisorSubstrings (int num, int k) {
4
5
string str = to_string (num);
5
6
int i = 0 , j = 0 , n = str.length ();
6
7
int ind = 0 ;
7
-
8
+
8
9
while (j < n)
9
10
{
10
11
if (j - i + 1 < k)
11
12
{
12
- // increment j till we get the window size
13
+ // increment j till we get the window size
13
14
++j;
14
15
}
15
16
else if (j - i + 1 == k)
16
17
{
17
- // on hiting the window size
18
- // extract window string and convert to int
19
- // check if it follows the given condition
18
+ // on hiting the window size
19
+ // extract window string and convert to int
20
+ // check if it follows the given condition
20
21
string s = str.substr (i,k);
21
22
int n = stoi (s);
22
23
if (n != 0 && num % n == 0 )
23
24
++ind;
24
-
25
- // shift the window by ++j;
26
- // remove previous calculation by ++i
25
+
26
+ // shift the window by ++j;
27
+ // remove previous calculation by ++i
27
28
++i;
28
29
++j;
29
30
}
30
-
31
+
31
32
}
32
-
33
+
33
34
return ind;
34
35
}
35
- };
36
+ };
You can’t perform that action at this time.
0 commit comments