C++ | [99%, 100% memory] | 10-liner | Crispy AF
\nclass Solution {\nprivate:\n    int done[100005];\npublic:\n    int smallestRepunitDivByK(int K) {\n        long long x = 0;\n        memset(done, 0, sizeof(d
```\nclass Solution {\nprivate:\n    int done[100005];\npublic:\n    int smallestRepunitDivByK(int K) {\n        long long x = 0;\n        memset(done, 0, sizeof(done));\n        \n        for (int i=1; ; i++) {\n            x = (x * 10 + 1) % K;\n            \n            if (x == 0) {\n                return i;\n            } else if (done[x]) {\n                return -1;\n            }\n            \n            done[x] = 1;\n        }\n    }\n};\n```\n\nExplanation -\n\n1. Calculate 1, 11, 111, 1111,..... modulo K\n2. If remainder becomes 0, return length. If remainder repeats, return -1\n3. ???\n4. Profit! \uD83E\uDD19\n\nAs always,\n\uD83E\uDD19 Stay crispy guys \uD83E\uDD19
[]