给定一个字符串数组 words,请计算当两个字符串 words[i] 和 words[j] 不包含相同字符时,它们长度的乘积的最大值。假设字符串中只包含英语的小写字母。如果没有不包含相同字符的一对字符串,返回 0。 public class Maximumproductofwords { public static void main(String[] args) { String []str={"abcd","ab","xfds","ddfasd"}; int i = maxProduct(str); System.out.println("best Maximum product of words:"+i); } public static int maxProduct(String[] words) { //将字符串转换为数组 int []word=new int[words.length]; for (int i = 0; i < words.length ; i++) { char[] chars=words[i].toCharArray(); for (int j = 0; j < chars.length; j++) { word[i]|=1<<(chars[j]-'a'); } } //双重循环找出最大乘积 int res=0; for (int i = 0; i < word.length; i++) { for (int j = i+1; j < word.length ; j++) { if ((word[i]&word[j])==0){ res=Math.max(res, words[i].length()*words[j].length()); } } } return res; } }