1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| func maxProduct(words []string) int { length := len(words) arr := make([]int, length) for i := 0; i < length; i++ { num := 0 for _, word := range words[i] { num |= 1 << int(word - 'a') } arr[i] = num } ans := 0 for i := 0; i < length; i++ { for j := 0; j < length; j++ { if arr[i] & arr[j] == 0 { ans = max(ans, len(words[i]) * len(words[j])) } } } return ans }
func max(num1, num2 int) int { if num1 >= num2 { return num1 } return num2 }
|