Java 7 Lines 1ms 99% Faster
First we get the total length of what the string is supposed to be after filling.\n- Then we create a stringbuilder appending those missing letters\n- We replac
- First we get the total length of what the string is supposed to be after filling.\n- Then we create a stringbuilder appending those missing letters\n- We replace `s` with the stringbuilder string\n- Finally, we copy each length `k` substring into `ans` array\n```Java\nclass Solution {\n    public String[] divideString(String s, int k, char fill) {\n        int n = s.length(), m = n % k, len = n + (m == 0? 0: k - m);\n        StringBuilder sb = new StringBuilder(s);\n        for (int i = 0; i < len - n; i++) sb.append(fill);\n        s = sb.toString();\n\n        String[] ans = new String[len / k];\n        for (int i = 0; i < len; i+=k)\n            ans[i/k] = s.substring(i, i + k);\n\n        return ans;\n    }\n}\n```
['Java']