Skip to content

Instantly share code, notes, and snippets.

@sergiosvieira
Created March 4, 2021 03:30
Show Gist options
  • Save sergiosvieira/01100f0fec06c2e1eb7a8ea9e0cb47b1 to your computer and use it in GitHub Desktop.
Save sergiosvieira/01100f0fec06c2e1eb7a8ea9e0cb47b1 to your computer and use it in GitHub Desktop.
First Not Repeating
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
char firstNotRepeatingCharacter(const std::string& s) {
for (const auto& c: s) {
if (s.find_first_of(c) == s.find_last_of(c)) return c;
}
return '_';
}
int main() {
std::cout << firstNotRepeatingCharacter("abacabad") << "\n";
std::cout << firstNotRepeatingCharacter("ngrhhqbhnsipkcoqjyviikvxbxyphsnjpdxkhtadltsuxbfbrkof") << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment