318. Maximum Product of Word Lengths Medium

@problem@discussion
#Array#String#Bit Manipulation



1/**
2 * [318] Maximum Product of Word Lengths
3 *
4 * Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.
5 *  
6 * Example 1:
7 * 
8 * Input: words = ["abcw","baz","foo","bar","xtfn","abcdef"]
9 * Output: 16
10 * Explanation: The two words can be "abcw", "xtfn".
11 * 
12 * Example 2:
13 * 
14 * Input: words = ["a","ab","abc","d","cd","bcd","abcd"]
15 * Output: 4
16 * Explanation: The two words can be "ab", "cd".
17 * 
18 * Example 3:
19 * 
20 * Input: words = ["a","aa","aaa","aaaa"]
21 * Output: 0
22 * Explanation: No such pair of words.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	2 <= words.length <= 1000
28 * 	1 <= words[i].length <= 1000
29 * 	words[i] consists only of lowercase English letters.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/maximum-product-of-word-lengths/
35// discuss: https://leetcode.com/problems/maximum-product-of-word-lengths/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn max_product(words: Vec<String>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_318() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.