package leetcode;

/**
 * https://leetcode.com/problems/reformat-phone-number/
 */
public class Problem1694 {
    public String reformatNumber(String number) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1694 prob = new Problem1694();
        System.out.println(prob.reformatNumber("1-23-45 6")); // "123-456"
        System.out.println(prob.reformatNumber("123 4-567")); // "123-45-67"
        System.out.println(prob.reformatNumber("123 4-5678")); // "123-456-78"
        System.out.println(prob.reformatNumber("12")); // "12"
        System.out.println(prob.reformatNumber("--17-5 229 35-39475 ")); // "175-229-353-94-75"
    }
}

@@ -165,524 +165,784 @@
     
-// TODO%0A        return null
+String num = number.replaceAll(%22-%22, %22%22).replaceAll(%22%5C%5Cs%22, %22%22);%0A        StringBuilder answer = new StringBuilder()
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1694 prob = new Problem1694();%0A        System.out.println(prob.reformatNumber(%221-23-45 6%22)); // %22123-456%22%0A        System.out.println(prob.reformatNumber(%22123 4-567%22)); // %22123-45-67%22%0A        System.out.println(prob.reformatNumber(%22123 4-5678%22)); // %22123-456-78%22%0A        System.out.println(prob.reformatNumber(%2212%22)); // %2212%22%0A        System.out.println(prob.reformatNumber(%22--17-5 229 35-39475 %22)); // %22175-229-353-94-75%22
+int count = 0;%0A        for (int i = 0; i %3C num.length(); i++) %7B%0A            if (num.length() %25 3 == 1 && num.length() - count == 4) %7B%0A                if (answer.length() %3E 0) %7B%0A                    answer.append(%22-%22);%0A                %7D%0A                answer.append(num, i, i + 2).append(%22-%22).append(num, i + 2, i + 4);%0A                break;%0A            %7D%0A            if (num.charAt(i) %3E= '0' && num.charAt(i) %3C= '9') %7B%0A                if (i %3E 0 && count %25 3 == 0) %7B%0A                    answer.append(%22-%22);%0A                %7D%0A                answer.append(num.charAt(i));%0A                count++;%0A            %7D%0A        %7D%0A        return answer.toString();
 %0A   

Solve problem 1694