Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Created February 23, 2022 15:00
Show Gist options
  • Save lyf-is-coding/4030389fbd046a723d40b01406837fac to your computer and use it in GitHub Desktop.
Save lyf-is-coding/4030389fbd046a723d40b01406837fac to your computer and use it in GitHub Desktop.
C++ STL Remove all consecutive duplicates from the string
// Input : aabbccaabb
// Output : abcab?????
// ^ return iterator
#include <string>
#include <algorithm>
std::string RemoveConecutiveDup(std::string str)
{
auto itr = std::unique(str.begin(), str.end());
return std::string(str.begin(), itr);
}
std::cout << RemoveConecutiveDup("aabbccaabb"); // abcab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment