1957.cpp (360B)
1 class Solution { 2 public: 3 string makeFancyString(string &s) const { 4 char prev = '\0'; 5 int i = 0, cnt = 0; 6 7 for (const char c : s) { 8 if (c == prev) 9 cnt++; 10 else 11 prev = c, cnt = 1; 12 if (cnt <= 2) s[i++] = c; 13 } 14 15 s.resize(i); 16 return s; 17 } 18 };