318 Maximum Product of Word Lengths 最大单词长度乘积
给定一个字符串数组words,找到length(word[i]) * length(word[j])的最大值,并且两个单词不含公共的字母。你可以认为每个单词只包含小写字母。如果不存在这样的两个单词,返回 0。
示例 1:
输入 ["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]
返回 16
两个单词可以为 "abcw", "xtfn"。
示例 2:
输入 ["a", "ab", "abc", "d", "cd", "bcd", "abcd"]
返回 4
两个单词可以为 "ab", "cd"。
示例 3:
输入 ["a", "aa", "aaa", "aaaa"]
返回 0
没有这样的两个单词。
详见:https://leetcode.com/problems/maximum-product-of-word-lengths/description/
class Solution {
public:
int maxProduct(vector<string>& words) {
int res=0;
vector<int> mask(words.size(),0);
for(int i=0;i<words.size();++i)
{
for(char c:words[i])
{
mask[i]|=1<<(c-'a');
}
for(int j=0;j<i;++j)
{
if(!(mask[i]&mask[j]))
{
res=max(res,int(words[i].size()*words[j].size()));
}
}
}
return res;
}
};
参考:http://www.cnblogs.com/grandyang/p/5090058.html
318 Maximum Product of Word Lengths 最大单词长度乘积的更多相关文章
- leetcode 318. Maximum Product of Word Lengths
传送门 318. Maximum Product of Word Lengths My Submissions QuestionEditorial Solution Total Accepted: 1 ...
- [leetcode]318. Maximum Product of Word Lengths单词长度最大乘积
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- 【LeetCode】318. Maximum Product of Word Lengths 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set 位运算 日期 题目地址:https://le ...
- 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- LeetCode 【318. Maximum Product of Word Lengths】
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- 318. Maximum Product of Word Lengths ——本质:英文单词中字符是否出现可以用26bit的整数表示
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- Java [Leetcode 318]Maximum Product of Word Lengths
题目描述: Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where ...
- leetcode@ [318] Maximum Product of Word Lengths (Bit Manipulations)
https://leetcode.com/problems/maximum-product-of-word-lengths/ Given a string array words, find the ...
- [LC] 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
随机推荐
- HTTP 请求的 GET 与 POST 方式的区别
HTTP 请求的 GET 与 POST 方式的区别 在客户机和服务器之间进行请求-响应时,两种最常被用到的方法是:GET 和 POST. GET - 从指定的资源请求数据. POST - 向指定的资源 ...
- github & Front-end JavaScript frameworks
github & Front-end JavaScript frameworks https://github.com/collections/front-end-javascript-fra ...
- 2.2 convex hull凸包
1.定义:一组平面上的点,求一个包含所有点的最小的凸多边形,就是凸包问题. 利用编程解决凸包问题,应该得到一组逆时针的顶点的顺序集合,在边上但不是顶点,则不包含在集合里. 2.机械的方法:将点所在的位 ...
- H - Tickets
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a ...
- GNS3和Cisco IOU搭建路由交换实验-IOU篇
http://www.mamicode.com/info-detail-605879.html
- mysql bin-log 设置
mysql 的事物日至为 [root@localhost mysql]# ls -ldtr mysql-bin.* -rw-rw---- mysql mysql 4月 : mysql-bin. -rw ...
- How to Use DHCP Relay over LAN? - DrayTek Corp
Assuming Vigor2960 has two LAN networks. Network Administrator wants that, when the internal DHCP is ...
- URAL 2031. Overturned Numbers (枚举)
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...
- 『干货』分享你最喜欢的技巧和提示(Xcode,objective-c,swift,c...等等)
亲爱的读者们,你们好 !年底将近,分享从过去一年你最喜欢的技巧和建议作为礼物送给新手们.提交你的最喜欢的迅速或objc琐事,实用的提示,意外的发现,实用的解决方法,没用的迷恋,或不论什么其它你认为今年 ...
- 【Angular】过滤器
AngularJS学习笔记 {{ name | uppercase}} {{ 123.456789 | number:2 }} app.controller('DemoController', ['$ ...