You are viewing a single comment's thread. Return to all comments →
Solution in C++:
vector<int> matchingStrings(vector<string> stringList, vector<string> queries) { std::unordered_map<std::string, int> strMap; for(auto s: stringList) { if(strMap.find(s) == strMap.end()) { strMap.insert(std::pair<string, int>(s, 1)); } else { strMap[s] += 1; } } vector<int> frequency; for(auto s: queries) { if(strMap.find(s) != strMap.end()) { frequency.push_back(strMap[s]); } else { frequency.push_back(0); } } return frequency; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Solution in C++: