Created
February 23, 2022 15:00
-
-
Save lyf-is-coding/4030389fbd046a723d40b01406837fac to your computer and use it in GitHub Desktop.
C++ STL Remove all consecutive duplicates from the string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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