leetcode -- Maximum Product of Word Lengths -- 重点
来源:互联网 发布:2016淘宝晚会 编辑:程序博客网 时间:2024/05/22 10:59
https://leetcode.com/problems/maximum-product-of-word-lengths/
主要思路:http://www.jianshu.com/p/bb84b0f866c9
用26 bit 的int来convert a word to a bit number.
最终solution还是O(
code参考:http://bookshadow.com/weblog/2015/12/16/leetcode-maximum-product-word-lengths/
class Solution(object): def maxProduct(self, words): """ :type words: List[str] :rtype: int """ nums = [] size = len(words) for w in words: nums += sum(1 << (ord(x) - ord('a')) for x in set(w))#这里就是把a存到第一位,把z存到第26位 ans = 0 for x in range(size): for y in range(size): if not (nums[x] & nums[y]): ans = max(len(words[x]) * len(words[y]), ans) return ans
0 0
- leetcode -- Maximum Product of Word Lengths -- 重点
- leetcode Maximum Product of Word Lengths
- Leetcode: Maximum Product of Word Lengths
- 【leetcode】318. Maximum Product of Word Lengths
- leetcode Maximum Product of Word Lengths
- Maximum Product of Word Lengths | LeetCode
- Leetcode: Maximum Product of Word Lengths
- LeetCode:Maximum Product of Word Lengths
- Leetcode: Maximum Product of Word Lengths
- [LeetCode 318] Maximum Product of Word Lengths
- LeetCode Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths LeetCode
- leetcode - Maximum Product of Word Lengths
- [leetcode] 318. Maximum Product of Word Lengths
- LeetCode: 318. Maximum Product of Word Lengths
- LeetCode 318. Maximum Product of Word Lengths
- leetcode 318. Maximum Product of Word Lengths
- LeetCode题解:Maximum Product of Word Lengths
- Java的日历程序
- Android面试之路1
- Hadoop与MapReduce。
- 关于R语言中set.seed()
- Java实例变量、类变量与局部变量
- leetcode -- Maximum Product of Word Lengths -- 重点
- Android的selector,背景选择器
- Windows下 Android Studio中获取SHA1的方法
- javascript 浏览器调用原理
- OC学习_8_内存管理_MRC
- Codeforces 597C Subsequences dp + 树状数组
- 黑马程序员——Java语言基础(下)
- Linux查看系统信息的一些命令及查看已安装软件包的命令(转)
- Redis和MongoDB原理简析