You are viewing a single comment's thread. Return to all comments →
My c++ solution using map, here is the explanation : https://youtu.be/0-xHzWDVAME
int anagram(string s) { if(s.size() % 2 == 1) return -1; map<char, int> mp; int ans = 0; for(int i = 0; i < s.size() / 2; i++) mp[s[i]]++; for(int i = s.size() / 2; i < s.size(); i++){ if(mp[s[i]] != 0) mp[s[i]]--; else ans++; } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
My c++ solution using map, here is the explanation : https://youtu.be/0-xHzWDVAME