EASY || BEGINNER || 3STEP DETAILED SOLUTION.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Initialization:\n\nC
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialization:\n\nCreate an empty stack st to store characters.\nProcess Characters:\n\nIterate through each character in the string:\nIf the stack is not empty and the top character matches the current character:\n2. Pop the top character from the stack to remove duplicates.\nOtherwise:\nPush the current character onto the stack.\n3. Build Result:\n\nCreate an empty StringBuilder to construct the result string.\nPop characters from the stack and append them to the StringBuilder.\nReverse the StringBuilder to get the correct order of characters.\nReturn the constructed string.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nlinear\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public String removeDuplicates(String s) {\n        Stack<Character> st = new Stack<>(); // Stack to store characters\n\n        // Process each character in the string\n        for (int i = 0; i < s.length(); i++) {\n            if (!st.isEmpty() && st.peek() == s.charAt(i)) {\n                // Remove duplicate character\n                st.pop();\n            } else {\n                // Push unique character\n                st.push(s.charAt(i));\n            }\n        }\n\n        // Build the result string in the correct order\n        StringBuilder sb = new StringBuilder("");\n        while (!st.isEmpty()) {\n            sb.append(st.pop());\n        }\n        return sb.reverse().toString(); // Reverse to get the original order\n    }\n}\n\n```
['Stack', 'Java']