package leetcode;

/**
 * https://leetcode.com/problems/license-key-formatting/
 */
public class Problem482 {
    public String licenseKeyFormatting(String S, int K) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem482 prob = new Problem482();
        System.out.println(prob.licenseKeyFormatting("2-4A0r7-4k", 4)); // 24A0-R74K
        System.out.println(prob.licenseKeyFormatting("2-4A0r7-4k", 3)); // 24-A0R-74K
    }
}

@@ -173,303 +173,391 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem482 prob = new Problem482();%0A        System.out.println(prob.licenseKeyFormatting(%222-4A0r7-4k%22, 4)); // 24A0-R74K%0A        System.out.println(prob.licenseKeyFormatting(%222-4A0r7-4k%22, 3)); // 24-A0R-74K
+StringBuilder sb = new StringBuilder();%0A        int count = 0;%0A        S = S.replaceAll(%22-%22, %22%22);%0A        for (int i = S.length() - 1; i %3E= 0; i--) %7B%0A            sb.append(S.charAt(i));%0A            count++;%0A            if (count == K && i != 0) %7B%0A                sb.append('-');%0A                count = 0;%0A            %7D%0A        %7D%0A        return sb.reverse().toString().toUpperCase();
 %0A   

Solve problem 482