class Solution {
public int smallestRepunitDivByK(int K) {
HashSet<Integer> set = new HashSet<>();
int sum = 0;
for (int i = 1; i <= 1000000; ++i) {
sum = (sum * 10 + 1) % K;
if (sum == 0)
return i;
if (set.contains(sum))
return -1;
set.add(sum);
}
return -1;
}
}
leetcode-1015. 可被 K 整除的最小整数
猜你喜欢
转载自blog.csdn.net/qq_39370495/article/details/89310744
今日推荐
周排行