Skip to content

Instantly share code, notes, and snippets.

@Meraj
Created February 9, 2021 18:30
Show Gist options
  • Select an option

  • Save Meraj/2e3f261daa922db147f52ee051e3079b to your computer and use it in GitHub Desktop.

Select an option

Save Meraj/2e3f261daa922db147f52ee051e3079b to your computer and use it in GitHub Desktop.

Revisions

  1. Meraj created this gist Feb 9, 2021.
    15 changes: 15 additions & 0 deletions removeDuplicates.cpp
    Original 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;
    }