首页 > 其他 > 详细

Maximum Product of word lengths

时间:2016-07-05 07:38:23      阅读:209      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!