318. 最大单词长度乘积

给你一个字符串数组 words ,找出并返回 length(words[i]) * length(words[j]) 的最大值,并且这两个单词不含有公共字母。如果不存在这样的两个单词,返回 0 。

示例 1:

输入:words = ["abcw","baz","foo","bar","xtfn","abcdef"]
输出:16 
解释这两个单词为 "abcw", "xtfn"

示例 2:

输入:words = ["a","ab","abc","d","cd","bcd","abcd"]
输出:4 
解释这两个单词为 "ab", "cd"

示例 3:

输入:words = ["a","aa","aaa","aaaa"]
输出:0 
解释不存在这样的两个单词。

提示:

  • 2 <= words.length <= 1000
  • 1 <= words[i].length <= 1000
  • words[i] 仅包含小写字母
    class Solution {
        public int maxProduct(String[] words) {
            //统计每个字符串在26字母中哪些存在,存在为1
            // 00 00000000 00000000 00000000
            // abcd
            // 00 00000000 00000000 00001111
            int flags[] = new int[words.length];
            
            for(int i = 0; i


    上面仅包含小写字母,如果是大小写一起呢?
     

    class Solution {
        public int maxProduct(String[] words) {
    
            //大写字母
            int UpperCase[] = new int[words.length];
            //小写字母
            int LowerCase[] = new int[words.length];
    
            for(int i = 0; i

你可能感兴趣的:(力扣,leetcode)