Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string removeDuplicates(string s, int k) {
- vector< pair<char, int> > v = {{0,'#'}};
- for(char c: s){
- if(v.back().first != c){
- v.push_back({c, 1});
- }
- else if(++v.back().second == k){
- v.pop_back();
- }
- }
- string ans = "";
- for(int i=1; i<v.size(); i++){
- ans.append(v[i].second, v[i].first);
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment