Maximum Product of Word Lengths
来源:互联网 发布:小伙领证前悔婚 知乎 编辑:程序博客网 时间:2024/05/17 06:39
一道位操作的好题。
当中的两个操作很好。
public class Solution { public int maxProduct(String[] words) { if (words == null || words.length == 0) { return 0; } int[] elements = new int[words.length]; for (int i = 0; i < words.length; i++) { String word = words[i]; for (int j = 0; j < word.length(); j++) { elements[i] = elements[i] | (1<<(word.charAt(j) - 'a')); } } int max = 0; for (int i = 0; i < words.length; i++) { for (int j = i + 1; j < words.length; j++) { if ((elements[i] & elements[j]) == 0) { max = Math.max(max, words[i].length()*words[j].length()); } } } return max; }}
0 0
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- Maximum Product of Word Lengths
- leetcode Maximum Product of Word Lengths
- Leetcode: Maximum Product of Word Lengths
- 【leetcode】318. Maximum Product of Word Lengths
- Leetcode202: Maximum Product of Word Lengths
- Android Studio improt project APIDemo
- Spyder配置
- 创建本地yum库
- RocketMQ集群配置
- 自定义控件的使用流程
- Maximum Product of Word Lengths
- ubuntu关闭Xwindow
- iOS开发之真机调试的情况下获取并查看数据库
- git学习
- c++ 初学者
- com/android/dx/command/dexer/Main : Unsupported major.minor version 52.0
- c语言基础
- OC和Swift中的Options
- iOS学习笔记-如何获取xib的autolayout后的frame