Making Anagrams

  • + 0 comments

    My C++ Solution:

    int makingAnagrams(string s1, string s2) {
        unordered_map<char, int> mp;
        int deletions = 0;
        for(auto c: s1){
            mp[c]++;
        }
        for(auto c: s2){
            if(mp[c]) mp[c]--;
            else{
                deletions++;
            }
        }
        for(auto item : mp){
            if(item.second > 0){
                deletions += item.second;
            }
        }
        return deletions;
    }