Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Complete Over-Use of Functor Templates (Academic Experiment)
Intersected Rectangles
top5words
test yield
list
cast
simple use of templete
no copy elision
Dar
Dijkstra
Please log in to post a comment.