Maximum Product of word lengths
Posted keepshuatishuati
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Maximum Product of word lengths相关的知识,希望对你有一定的参考价值。
1 public class Solution { 2 public int maxProduct(String[] words) { 3 if (words.length < 2) { 4 return 0; 5 } 6 7 int[] bitMap = new int[words.length]; 8 for (int i = 0; i < words.length; i++) { 9 for (char c : words[i].toCharArray()) { 10 bitMap[i] |= 1 << (int)(c - ‘a‘); 11 } 12 } 13 14 int result = 0; 15 for (int i = 0; i < words.length; i++) { 16 for (int j = i + 1; j < words.length; j++) { 17 if ((bitMap[i] & bitMap[j]) == 0) { 18 result = Math.max(result, words[i].length() * words[j].length()); 19 } 20 } 21 } 22 return result; 23 } 24 }
1. Do not forget to left shift the number.
以上是关于Maximum Product of word lengths的主要内容,如果未能解决你的问题,请参考以下文章
318. Maximum Product of Word Lengths
318. Maximum Product of Word Lengths
318. Maximum Product of Word Lengths
318. Maximum Product of Word Lengths