You are viewing a single comment's thread. Return to all comments →
C++
int makingAnagrams(string s1, string s2) { vector<int> vec1(26, 0); vector<int> vec2(26, 0); int common = 0; for (int i = 0; i < s1.size(); i++) vec1[s1[i] - 'a']++; for (int i = 0; i < s2.size(); i++) vec2[s2[i] - 'a']++; for (int i = 0; i < 26; i++) { int freq1 = vec1[i]; int freq2 = vec2[i]; if (freq1 != 0 && freq2 != 0) common += min(freq1, freq2); } return s1.length() + s2.length() - 2 * common; }
Seems like cookies are disabled on this browser, please enable them to open this website
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
C++