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

leetcode318

时间:2017-06-08 11:00:29      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:val   span   desc   public   ring   maximum   amp   ref   i++   

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

标签:val   span   desc   public   ring   maximum   amp   ref   i++   

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

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