首页 > 其他 > 详细

leetcode318

时间:2017-06-08 10:16:10      阅读:302      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public int MaxProduct(string[] words) {
        if (words == null || words.Length == 0)
            {
                return 0;
            }
            int len = words.Length;
            int[] value = new int[len];
            for (int i = 0; i < len; i++)
            {
                string tmp = words[i];
                value[i] = 0;
                for (int j = 0; j < tmp.Length; j++)
                {
                    value[i] |= 1 << (tmp[j] - a);
                }
            }
            int maxProduct = 0;
            for (int i = 0; i < len; i++)
            {
                for (int j = i + 1; j < len; j++)
                {
                    if ((value[i] & value[j]) == 0 && (words[i].Length * words[j].Length > maxProduct))
                    {
                        maxProduct = words[i].Length * words[j].Length;
                    }
                }
            }
            return maxProduct;
    }
}

https://leetcode.com/problems/maximum-product-of-word-lengths/#/description

leetcode318

原文:http://www.cnblogs.com/asenyang/p/6960944.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!