318. Maximum Product of Word Lengths
来源:互联网 发布:nginx php 空白 编辑:程序博客网 时间:2024/06/01 19:26
题目:https://leetcode.com/problems/maximum-product-of-word-lengths/
代码:
思路: 用marks数组来区分两个字符串是否有相同的字母。在本程序中每个字母对应一位的1,比如a对应1,b对应10(二进制),c对应100.。。。。。。那么如果marks与一下是0的话说明没有相同的字母public class Solution { public int maxProduct(String[] words) { int[] marks = new int[words.length]; for(int i=0;i<marks.length;i++) { char[] temp = words[i].toCharArray(); for(int j=0;j<temp.length;j++) { int p = (int)(temp[j]-'a'); p = 1<<p; marks[i] |= p; } } int max = 0; for(int i=0;i<marks.length;i++) { for(int j=i+1;j<marks.length;j++) { if((marks[i]&marks[j])==0) max = Math.max(max,words[i].length()*words[j].length()); } } return max; }}33ms
0 0
- 【leetcode】318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths LeetCode
- [leetcode] 318. Maximum Product of Word Lengths
- 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
- 318. Maximum Product of Word Lengths
- [LeetCode]318. Maximum Product of Word Lengths
- [LeetCode]318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- LeetCode 318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- LeetCode *** 318. Maximum Product of Word Lengths
- 318. Maximum Product of Word Lengths
- git
- FILE文件流的中fopen、fread、fseek、fclose的使用
- Linux串口编程(向空调发送十六进制指令)
- 基于RESTful Web Service 的Jersey框架与Spring完美整合
- FastDFS的Tracker Server-tracker.conf 配置说明
- 318. Maximum Product of Word Lengths
- QT线程编程-串口收发
- PAT乙级练习题B1047. 编程团体赛
- Leetcode 219. Contains Duplicate II (Easy) (cpp)
- Linux apt-get install过程中出现“size mismatch”
- Windows 7环境下配置Java Web开发环境
- curl
- KVM API使用简单示例
- POJ2378(树形DP)