Created
March 4, 2021 03:30
-
-
Save sergiosvieira/01100f0fec06c2e1eb7a8ea9e0cb47b1 to your computer and use it in GitHub Desktop.
First Not Repeating
This file contains 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
#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