We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 846bd63 commit c55f16dCopy full SHA for c55f16d
318-maximum-product-of-word-lengths.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {string[]} words
3
+ * @return {number}
4
+ */
5
+const maxProduct = function(words) {
6
+ if (words == null || words.length === 0) return 0;
7
+ let len = words.length;
8
+ let value = [];
9
+ for (let i = 0; i < len; i++) {
10
+ let tmp = words[i];
11
+ value[i] = 0;
12
+ for (let j = 0; j < tmp.length; j++) {
13
+ value[i] |= 1 << (tmp.charAt(j).charCodeAt(0) - "a".charCodeAt(0));
14
+ }
15
16
+ let maxProductNum = 0;
17
+ for (let i = 0; i < len; i++)
18
+ for (let j = i + 1; j < len; j++) {
19
+ if (
20
+ (value[i] & value[j]) === 0 &&
21
+ words[i].length * words[j].length > maxProductNum
22
+ )
23
+ maxProductNum = words[i].length * words[j].length;
24
25
+ return maxProductNum;
26
+};
0 commit comments