318. Maximum Product of Word Lengths

Given a string arraywords, find the maximum value oflength(word[i]) * length(word[j])where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0.
Example 1:
Given["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]
Return16
The two words can be"abcw", "xtfn".

免得字符串排序判断是否有相同字符, 采用二进制数值的方式, 每个字符串做多有26种字幕, 每个字母对应一个二进制位, 每个字符串就是一个数字, 最后数字两两与, 如果==0 , 则证明没有相同字符。 然后再求最大乘积。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容