题目大意:给出一些字符串,找出两个不同的字符串之间长度之积的最大值,但要求这两个字符串之间不能拥有相同的字符。(字符只考虑小写字母)。

题目分析:字符最多只有26个,因此每个字符串可以用一个二进制数来表示它含有哪些字符。

代码如下:

class Solution {
public:
int maxProduct(vector<string>& words) {
int maxn=0;
int *Bit=new int[words.size()];
fill(Bit,Bit+words.size(),0);
for(int i=0;i<words.size();++i){
int t=0;
for(int j=0;j<words[i].size();++j)
Bit[i]|=(1<<(words[i][j]-'a'));
for(int j=0;j<i;++j){
if(Bit[i]&Bit[j]) continue;
maxn=max(maxn,(int)(words[i].size()*words[j].size()));
}
}
delete []Bit;
return maxn;
}
};

  

LeetCode 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 (Bit Manipulations)

    https://leetcode.com/problems/maximum-product-of-word-lengths/ Given a string array words, find the ...

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

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

  5. Leetcode 318 Maximum Product of Word Lengths 字符串处理+位运算

    先介绍下本题的题意: 在一个字符串组成的数组words中,找出max{Length(words[i]) * Length(words[j]) },其中words[i]和words[j]中没有相同的字母 ...

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

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

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

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

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

随机推荐

  1. PHP empty、isset、isnull的区别

    PHP empty.isset.isnull的区别 empty 如果 变量 是非空或非零的值,则 empty() 返回 FALSE.换句话说,”".0.”0″.NULL.FALSE.arra ...

  2. mysql日志文件目录

    默认情况下mysql的二进制日志文件保存在默认的数据目录data下,如:/usr/local/mysql/data 修改日志保存目录(/backup/mysqlbinlog/mysql-bin)的话: ...

  3. where T : class含义

    .NET支持的类型参数约束有以下五种: where T : struct                               | T必须是一个结构类型where T : class       ...

  4. String内存分析,for-each,参数传递

    上午总结: 蓝白书P245 (一)Iterator用法 import java.util.*; public class HashSetTest{ public static void main(St ...

  5. .net Core 中将原MVC中的 MvcHtmlString转换

    public static IHtmlContent CustomLabelFor<TModel, TProperty>(this IHtmlHelper helper, Expressi ...

  6. 用Nodejs连接MySQL(原文链接)

    原文链接:http://blog.fens.me/nodejs-mysql-intro/

  7. 20145104张家明 《Java程序设计》第7周学习总结

    20145104张家明 <Java程序设计>第7周学习总结 教材学习内容总结 第13章 简单认识时间和日期 -时间的度量:GMT.UT.TAI.UTC.Unix.epoch. -UTC:保 ...

  8. 20145118 《Java程序设计》 实验报告四

    实验要求 基于Android Studio开发简单的Android应用并部署测试; 了解Android组件.布局管理器的使用: 掌握Android中事件处理机制: Android Studio安装 实 ...

  9. 20144303石宇森《网络对抗》Web安全基础实践

    20144303石宇森<网络对抗>Web安全基础实践 实验后问题回答 SQL注入攻击原理,如何防御: SQL攻击时通过在输入框中输入语句,构造出SQL命令,把这段命令注入到表单中,让后台的 ...

  10. flink架构介绍

    前言 flink作为基于流的大数据计算引擎,可以说在大数据领域的红人,下面对flink-1.7的架构进行逻辑上的分析并和spark做了一些关键点的对比. 架构 如图1,flink架构分为3个部分,cl ...