@@ -0,0 +1,1634 @@
+package com.cyq7on.leetcode.stack;%0A%0A%0Aimport java.util.Stack;%0A%0A/**%0A * @author cyq7on%0A * @description Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.%0A * %3Cp%3E%0A * We repeatedly make duplicate removals on S until we no longer can.%0A * %3Cp%3E%0A * Return the final string after all such duplicate removals have been made.  It is guaranteed the answer is unique.%0A * %3Cp%3E%0A * %3Cp%3E%0A * %3Cp%3E%0A * Example 1:%0A * %3Cp%3E%0A * Input: %22abbaca%22%0A * Output: %22ca%22%0A * Explanation:%0A * For example, in %22abbaca%22 we could remove %22bb%22 since the letters are adjacent and equal, and this is the only possible move.%0A * The result of this move is that the string is %22aaca%22, of which only %22aa%22 is possible, so the final string is %22ca%22.%0A * @create 2019/12/11%0A **/%0Apublic class RemoveAllAdjacentDuplicatesInString %7B%0A%0A%0A    public String removeDuplicates(String s) %7B%0A        Stack%3CCharacter%3E stack = new Stack%3C%3E();%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            char c = s.charAt(i);%0A            if (stack.isEmpty() %7C%7C stack.peek() != c) %7B%0A                stack.push(c);%0A            %7Delse %7B%0A                stack.pop();%0A            %7D%0A        %7D%0A        int size = stack.size();%0A        char%5B%5D chars = new char%5Bsize%5D;%0A        for (int i = 0; i %3C size; i++) %7B%0A            chars%5Bsize - i - 1%5D = stack.pop();%0A        %7D%0A        return new String(chars);%0A    %7D%0A%0A%0A    public static void main(String%5B%5D args) %7B%0A        RemoveAllAdjacentDuplicatesInString duplicatesInString = new RemoveAllAdjacentDuplicatesInString();%0A        System.out.println(duplicatesInString.removeDuplicates(%22abbaca%22));%0A    %7D%0A%7D%0A

Remove All Adjacent Duplicates In String