classSolution { public: unsignedto_uword(const string &word){ unsigned res = 0; for (auto &&c: word) { res |= 1 << (c - 'a'); } return res; }
intmaxProduct(vector<string>& words){ vector<unsigned> uwords; uwords.reserve(words.size()); for (auto &&w: words) { uwords.push_back(to_uword(w)); } int m = 0; int n = words.size(); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { auto &s1 = uwords[i]; auto &s2 = uwords[j]; if (s1 & s2) continue; if (int r = words[i].size() * words[j].size(); r > m) m = r; } } return m; } };