You are viewing a single comment's thread. Return to all comments →
The 'not so elegant' version, if you are having trouble understanding this one:
int number_needed(string a, string b) { vector<int> freq(26, 0); int count=0; for(int i=0; i<a.length(); i++) { freq[a[i]-'a']+=1; } for(int i=0; i<b.length(); i++) { freq[b[i]-'a']-=1; } for(int i=0; i<26; i++) { count+=abs(freq[i]); } return count; }
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
The 'not so elegant' version, if you are having trouble understanding this one: