You are viewing a single comment's thread. Return to all comments →
int makingAnagrams(string s1, string s2) { int b[123] = {0}; int size1 = s1.size(); int size2 = s2.size(); for(int i = 0; i < size2; i++) b[s2[i]]++; int count = 0; for(int i = 0; i < size1; i++) { if(b[s1[i]] > 0) { count++; b[s1[i]]--; } } return size1 + size2 - 2 * count; }
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 →
int makingAnagrams(string s1, string s2) { int b[123] = {0}; int size1 = s1.size(); int size2 = s2.size(); for(int i = 0; i < size2; i++) b[s2[i]]++; int count = 0; for(int i = 0; i < size1; i++) { if(b[s1[i]] > 0) { count++; b[s1[i]]--; } } return size1 + size2 - 2 * count; }