Smallest Integer Divisible by K | Java | O(n) | 85% faster |
class Solution {\n\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n        int remainder = 0;\n        for (in
class Solution {\n\n    public int smallestRepunitDivByK(int k) {\n        if (k % 2 == 0 || k % 5 == 0) return -1;\n        int remainder = 0;\n        for (int i = 1; i <= k; i++) {\n            remainder = (remainder * 10 + 1) % k;\n            if (remainder == 0) return i;\n        }\n        return -1;\n    }\n}\n**Please help to UPVOTE if this post is useful for you.\nIf you have any questions, feel free to comment below.\nHAPPY CODING :)\nLOVE CODING :)**
['Math']