给定一个字符串数组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 最大单词长度乘积的更多相关文章

  1. leetcode 318. Maximum Product of Word Lengths

    传送门 318. Maximum Product of Word Lengths My Submissions QuestionEditorial Solution Total Accepted: 1 ...

  2. [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 ...

  3. 【LeetCode】318. Maximum Product of Word Lengths 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set 位运算 日期 题目地址:https://le ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. [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 ...

随机推荐

  1. 邮票(codevs 2033)

    题目描述 Description 已知一个 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 K 张邮票.计算从 1 到 M 的最大连续可贴出的邮资. 例如,假设有 ...

  2. [COGS309] [USACO 3.2] 香甜的黄油

    ★★   输入文件:butter.in   输出文件:butter.out   简单对比 时间限制:1 s   内存限制:128 MB 描述 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖.把糖 ...

  3. [bzoj2038][2009国家集训队]小Z的袜子(hose)_莫队

    小Z的袜子 hose 2009-国家集训队 bzoj-2038 题目大意:给定一个n个袜子的序列,每个袜子有一个颜色.m次询问:每次询问一段区间中每种颜色袜子个数的平方和. 注释:$1\le n,m\ ...

  4. Android开发系列(二十四):Notification的功能与使用方法

    关于消息的提示有两种:一种是Toast,一种就是Notification.前者维持的时间比較短暂.后者维持的时间比較长. 并且我们寻常手机的应用比方网易.贴吧等等都有非常多的推送消息,就是用Notif ...

  5. JobHistory搜索智能化

    前言 做过hadoop集群问题排查工作的同学一定用过JobHistory,这是一个非常好用的"利器",为什么这么说呢?正如这个工具的名称所叫的那样,这个工具能帮你找到历史Job跑过 ...

  6. HTTPS那些事 用java实现HTTPS工作原理

    HTTPS那些事 用java实现HTTPS工作原理 博客分类: java历险   今天被问到关于https原理的问题,结果由于知识掌握不牢靠,停留于表面,很多细节都无法回答清楚,于是决定把https的 ...

  7. 【OI】向量&矩阵乘法

    何为向量? 在初中课本中,我们知道: 向量是有大小和方向的量. 这样解释太笼统了,现在我们只讨论平面上的向量. 那么,我们约定:在平面上的向量,由一个二元组组成:如α(c1,c2). 在此平面上建立一 ...

  8. C++中switch 语句中的变量声明和

    switch 内部的变量定义: ; switch(i) { : string str; //error ; //error int val2; //right ; //right : val2 = ; ...

  9. ios16--自定义控件1

    k控制器: // // XMGViewController.h #import <UIKit/UIKit.h> @interface XMGViewController : UIViewC ...

  10. 【总结】嵌入式linux内核中Makefile、Kconfig、.config的关系及增加开机Hello World【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/73772109 为了弄清内核的组织结构,我们先来实现下面这个简单的例子. 一.增加 ...