aboutsummaryrefslogtreecommitdiff
path: root/remove_adjacent_dup_str.cpp
blob: 80b61abba7015ec782f9fd4c6816fe1fa6149d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "leetcode.h"

class Solution {
public:
  string removeDuplicates(string s) {
    string ans;
    for (char &c : s) {
      if (ans.size() && c == ans.back())
        ans.pop_back();
      else
        ans.push_back(c);
    }
    return ans;
  }
};

int main() {
  Solution obj;
  cout << obj.removeDuplicates("abbaca");
}