leetcode318

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

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