package leetcode;

/**
 * https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/
 */
public class Problem1209 {
    public String removeDuplicates(String s, int k) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1209 prob = new Problem1209();
        System.out.println(prob.removeDuplicates("abcd", 2)); // "abcd"
        System.out.println(prob.removeDuplicates("deeedbbcccbdaa", 3)); // "aa"
        System.out.println(prob.removeDuplicates("pbbcggttciiippooaais", 2)); // "ps"
    }
}

@@ -191,35 +191,874 @@
     
-// TODO%0A        return null
+String answer = s;%0A        while (true) %7B%0A            boolean found = false;%0A            int count = 1;%0A            String tmp = %22%22;%0A            int i = 0;%0A            while (i %3C answer.length() - 1) %7B%0A                if (answer.charAt(i) == answer.charAt(i + 1)) %7B%0A                    count++;%0A                %7D else %7B%0A                    count = 1;%0A                %7D%0A                tmp += answer.charAt(i);%0A                if (count == k) %7B%0A                    tmp += answer.charAt(i + 1);%0A                    tmp = tmp.substring(0, tmp.length() - k);%0A                    found = true;%0A                    i++;%0A                    count = 1;%0A                %7D%0A                i++;%0A            %7D%0A            if (!found) %7B%0A                break;%0A            %7D%0A            answer = tmp + (i %3C answer.length() ? answer.charAt(i) : %22%22);%0A        %7D%0A        return answer
 ;%0A  
@@ -1104,16 +1104,33 @@
 %5B%5D args)
+ throws Exception
  %7B%0A     

Update problem 1209