First Letter to Appear Twice LeetCode solution in C++
1class Solution {2public:3char repeatedCharacter(string s) {4unordered_map<char, int> mp; // for storing occurrences of char56char ans;7for (auto it : s) {8if (mp.find(it) != mp.end()) // any char which comes twice first will be the ans;9{10ans = it;11break;12}13mp[it]++; // increase the count of char14}15return ans;16}17};