Created
February 9, 2021 18:30
-
-
Save Meraj/2e3f261daa922db147f52ee051e3079b to your computer and use it in GitHub Desktop.
Revisions
-
Meraj created this gist
Feb 9, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ /** * remove Duplicate letters in a text * @param textString * @return */ string removeDuplicates(std::string textString) { if (textString.begin() == textString.end()) return textString; auto no_duplicates = textString.begin(); for (auto current = no_duplicates; current != textString.end();) { current = std::find_if(std::next(current), textString.end(), [no_duplicates](const char c) { return c != *no_duplicates; }); *++no_duplicates = std::move(*current);; } textString.erase(++no_duplicates, textString.end()); return textString; }