码迷,mamicode.com
首页 > 其他好文 > 详细

Maximum Product of word lengths

时间:2016-07-05 07:38:40      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

 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

标签:

原文地址:http://www.cnblogs.com/shuashuashua/p/5642230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!