java short easy solution 21ms 80%


  • 0
    public String licenseKeyFormatting(String S, int K) {
            StringBuilder res = new StringBuilder(S.replaceAll("-",""));
            int k = string.length() - K;
            while(k > 0) {
                res.insert(k,"-");
                k -= K;
            }
            return res.toString().toUpperCase();
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.