Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string removeDuplicates(string s) {
- int i = 0, n = s.length();
- for (int j = 0; j < n; ++j, ++i) {
- s[i] = s[j];
- if (i > 0 && s[i - 1] == s[i]) // count = 2
- i -= 2;
- }
- return s.substr(0, i);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment