Posted on

Description

Submission

class Solution {
public:
    string removeDuplicates(string S) {
        string ret = "";
        for(char c: S) {
            if(ret.empty()) {
                ret.push_back(c);
                continue;
            }

            if(c == ret.back()) ret.pop_back();
            else {
                ret.push_back(c);
            }
        }

        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *