Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- in: daabbcccbbaad out: dd
- in: aaabbb out:
- in: aaabbbc out: c
- void removeDup(string& s, int start) {
- if (s.length() < 3) {
- return;
- }
- if (start > s.length() - 2) return;
- int count = 1;
- char c = s[start];
- int i = start + 1;
- while (i < s.length() && s[i] == c) {
- ++count, ++i;
- }
- if (count >= 3) {
- start = i - count - 2;
- if (start < 0) start = 0;
- s.erase(i - count, count);
- } else {
- start = i;
- }
- return removeDup(s, start);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement