Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
find first non repeating
// 3. Find first non-repeating character in String // ex: geeksforgeeks: f // geeksforgeeksFirst:o #include <iostream> #include <string> #include <unordered_map> using namespace std; char findFirstNoneRepeating(const string& s) { unordered_map<char, int> m; for (unsigned i = 0; i < s.length(); ++i) { char c = tolower(s[i]); if (m.find(c) == m.end()) m[c] = 1; else ++m[c]; } auto best = m.begin(); bool found = false; for (auto it = m.begin(); it != m.end(); ++it) if (it->second == 1) { best = it; found = true; } return (found) ? (best->first) : '-'; } int main() { cout << findFirstNoneRepeating("gggccaaabbb") << endl; cout << findFirstNoneRepeating("geeksforgeeks") << endl; cout << findFirstNoneRepeating("geeksforgeeksFirst") << endl; }
run
|
edit
|
history
|
help
0
Primality test Fermat primality test
CAE C++ Day 3 tests
maximize the difference
Sort array of 0's and 1's
Luces led con relé
UnghiLansator
Raw AVL
Wipro Problem 1
RegExpress
Bitset Operators