Maximum Product of Word Lengths LeetCode solution in C++
1class Solution {2public:3int maxProduct(vector<string> &words) {4vector<unordered_set<char>> st;5int res = 0;6for (string s : words) {7unordered_set<char> temp;8for (char c : s) {9temp.insert(c);10}11st.push_back(temp);12}13for (int i = 0; i < words.size(); i++) {14for (int j = 0; j < i; j++) {15bool flag = false;16for (auto val : st[i]) {17if (st[j].find(val) != st[j].end()) {18flag = true;19break;20}21}22if (flag == false) {23int prd = words[i].length() * words[j].length();24res = max(res, prd);25}26}27}28return res;29}30};