package leetcode;

/**
 * https://leetcode.com/problems/reformat-the-string/
 */
public class Problem1417 {
    public String reformat(String s) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1417 prob = new Problem1417();
        System.out.println(prob.reformat("a0b1c2")); // "0a1b2c"
        System.out.println(prob.reformat("leetcode")); // ""
        System.out.println(prob.reformat("1229857369")); // ""
        System.out.println(prob.reformat("covid2019")); // "c2o0v1i9d"
        System.out.println(prob.reformat("ab123")); // "1a2b3"
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -204,260 +204,765 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1417 prob = new Problem1417();%0A        System.out.println(prob.reformat(%22a0b1c2%22)); // %220a1b2c%22%0A        System.out.println(prob.reformat(%22leetcode%22)); //
+List%3CCharacter%3E chars = new ArrayList%3C%3E();%0A        List%3CCharacter%3E numbers = new ArrayList%3C%3E();%0A        for (char c : s.toCharArray()) %7B%0A            if (c %3E= '0' && c %3C= '9') %7B%0A                numbers.add(c);%0A            %7D else %7B%0A                chars.add(c);%0A            %7D%0A        %7D%0A        if (Math.abs(chars.size() - numbers.size()) %3E 1) %7B%0A            return %22%22;%0A        %7D%0A        String answer = %22%22;%0A        boolean isNumber = chars.size() %3C= numbers.size();%0A        int i = 0;%0A        int j = 0;%0A        while (i %3C chars.size() && j %3C numbers.size()) %7B%0A            answer += isNumber ? numbers.get(i++) : chars.get(j++);%0A            isNumber = !isNumber;%0A        %7D%0A        if (isNumber) %7B%0A            answer += i %3C numbers.size() ? numbers.get(i) :
  %22%22
+;
 %0A   
@@ -970,62 +970,59 @@
     
-System.out.println(prob.reformat(%221229857369%22)); //
+    answer += j %3C chars.size() ? chars.get(j) :
  %22%22
+;
 %0A   
@@ -1030,133 +1030,173 @@
     
-System.out.println(prob.reformat(%22covid2019%22)); // %22c2o0v1i9d%22%0A        System.out.println(prob.reformat(%22ab123%22)); // %221a2b3%22
+%7D else %7B%0A            answer += j %3C chars.size() ? chars.get(j) : %22%22;%0A            answer += i %3C numbers.size() ? numbers.get(i) : %22%22;%0A        %7D%0A        return answer;
 %0A   

Solve problem 1417