Remove All Adjacent Duplicates in String II
[LeetCode] Remove All Adjacent Duplicates in String II
string removeDuplicates(string str, int k) { stack s; auto begin = str.begin(), end = str.end(); while (begin != end) { auto ch = *begin; if (!s.empty()) { auto& top = s.top(); if (top.first != ch) s.push({ ch, 1 }); else top.second++; if (top.second == k) s.pop(); } else s.push({ ch, 1 }); begin++; } str.clear(); while (!s.empty()) { auto top = s.top(); for (int i = 0; i < top.second; i++) str...