You are viewing a single comment's thread. Return to all comments →
Efficient? No. Solution? Yes.
void deDup(string &str) { sort(str.begin(), str.end()); auto last = std::unique(str.begin(), str.end()); str.erase(last, str.end()); } int gemstones(vector<string> arr) { map<char, int> aparitions; for(int i=0; i<arr.size(); i++){ deDup(arr[i]); for(int j=0; j<arr[i].size(); j++){ aparitions[arr[i][j]] += 1; } } int rocks = 0; for (auto& pair : aparitions){ if(pair.second==arr.size()){ rocks++; } } return rocks; }
Seems like cookies are disabled on this browser, please enable them to open this website
Gemstones
You are viewing a single comment's thread. Return to all comments →
Efficient? No. Solution? Yes.