剑指 Offer II 005. 单词长度的最大乘积
去重,然后暴力即可,去重时别忘了记录原来的长度
class Solution { public: int max(int a, int b) { return a > b ? a : b; } int maxProduct(vector<string>& words) { int len = words.size(); vector<string> ww; int a[1001]; bool vis[26]; bool vv[1001][26]; memset(vv, 0, sizeof(vv)); for(int i = 0; i < len; i++) { string temp = ""; memset(vis, 0, sizeof(vis)); a[i] = words[i].length(); for(int j = 0; j < a[i]; j++) if(vis[words[i][j] - 'a'] == 0) { temp += words[i][j], vis[words[i][j] - 'a'] = 1; vv[i][words[i][j] - 'a'] = 1; } ww.push_back(temp); } int sum = 0; for(int i = 0; i < len; i++) { string temp = ww[i]; int len1 = temp.length(); bool flag = 0; for(int j = i + 1; j < len; j++) { flag = 0; for(int k = 0; k < len1; k++) { if(vv[j][temp[k] - 'a']) { flag = 1; break; } } if(flag == 0) sum = max(sum, a[j] * a[i]); } } return sum; } };
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。