Find the K-Beauty of a Number LeetCode solution in Java

1
class Solution {
2
public int divisorSubstrings(int num, int k) {
3
String str = String.valueOf(num); // to covert integer to String
4
int count = 0; // count of ans..
5
for (int i = 0; i < str.length() - k + 1; i++) // deciding the starting index of window
6
{
7
String temp = str.substring(i, i + k); // storing string till window length
8
int n1 = Integer.valueOf(temp); // converting string to integer
9
if (n1 == 0) // to avoid division error
10
{
11
continue;
12
}
13
if (num % n1 == 0) // if it is divisible then increase the count
14
{
15
count++;
16
}
17
}
18
return count; // lastly return our count
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0