> For the complete documentation index, see [llms.txt](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/14-character-array-and-strings/discord-homework/08.-remove-all-the-adjacent-duplicates.md).

# 08. Remove all the adjacent duplicates

[Link](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/)

```cpp
string removeDuplicates(string s) {
    stack<char> st;
    for(char ch: s)
        if(!st.empty() && st.top() == ch)
            st.pop();
        else
            st.push(ch);
    string res = "";
    while(!st.empty()) {
        res += st.top();
        st.pop();
    }

    reverse(res.begin(), res.end());
    return res;
}
```
