mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
routine
This commit is contained in:
17
25/12/comp/28q3.cpp
Normal file
17
25/12/comp/28q3.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
class Solution {
|
||||
public:
|
||||
int minAllOneMultiple(int k) {
|
||||
if (k%2==0 || k%5==0) {
|
||||
return -1;
|
||||
}
|
||||
int remainder = 1;
|
||||
for (int i = 1 ;i<=k;i++) {
|
||||
if (remainder % k == 0) {
|
||||
return i;
|
||||
}
|
||||
// (a * 10 + 1) % k = ((a % k) * 10 + 1) % k
|
||||
remainder = (remainder * 10 + 1) % k;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user