You are viewing a single comment's thread. Return to all comments →
Pretty close to your solution, here's mine
bool ransom_note(vector<string> magazine, vector<string> ransom) { unordered_map<string, int> map_word; for(auto const& word: magazine) { map_word[word]++; } for (auto const& word: ransom) { const auto it = map_word.find(word); if ( it == map_word.end() || (it->second = --it->second) < 0 ) { return false; } } return true; }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
Pretty close to your solution, here's mine