static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
string longestWord(vector<string>& words)
{
unordered_set<string> siset(words.begin(),words.end());
string res;
for(string s:words)
{
if(s.length()>res.length()||(s.length()==res.length()&&s<res))
{
if(judgein(siset,s))
res=s;
}
else
continue;
}
return res;
} bool judgein(unordered_set<string> &siset,string s)
{
while(!s.empty())
{
if(siset.find(s)!=siset.end())
s.pop_back();
else
return false;
}
return true;
}
};

用一个set将原容器中的字符串扫描进去,然后顺序扫描字符串容器,只有当当前字符串长度长于res或者长度和res相等但是小于res时,才调用判定函数判定该字符串是否能由容器中的单词序列构成,若判定结果为真,则更新res。

720. Longest Word in Dictionary的更多相关文章

  1. 【Leetcode_easy】720. Longest Word in Dictionary

    problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...

  2. [LeetCode&Python] Problem 720. Longest Word in Dictionary

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  3. leetcode 720. Longest Word in Dictionary

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  4. 720. Longest Word in Dictionary 能连续拼接出来的最长单词

    [抄题]: Given a list of strings words representing an English Dictionary, find the longest word in wor ...

  5. LeetCode 720. Longest Word in Dictionary (字典里最长的单词)

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  6. 【LeetCode】720. Longest Word in Dictionary 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力查找 排序 日期 题目地址:https://le ...

  7. [leetcode]720. Longest Word in Dictionary字典中最长的单词

    b.compareTo(a) 这个函数是比较两个值得大小,如果b比a大,那么返回1 如果小,那么返回-1,相等返回0 如果比较的是字符串,那么比较字典编纂顺序,b靠前返回-1,靠后返回1 这个题的核心 ...

  8. [LeetCode] Longest Word in Dictionary 字典中的最长单词

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  9. Longest Word in Dictionary through Deleting - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Longest Word in Dictionary through Deleting - LeetCode 注意点 长度一样的字符串要按字典序返回较小的 ...

随机推荐

  1. 排列组合或容斥原理 SPOJ - AMR11H

    题目链接: https://vjudge.net/contest/237052#problem/H 这里给你一串数字,让你计算同时拥有这串数字最大值和最小值的子集(连续)和子序列(可以不连续)的数量, ...

  2. 发送邮件【文本-html】【图片】【邮件】【附件】

    依赖 <!-- https://mvnrepository.com/artifact/javax.mail/mail --> <dependency> <groupId& ...

  3. 利用crontab每天定时备份MySQL数据库

    当数据库服务器建立并正式投入生产使用后,我们不得不担忧一个问题:当数据库遭到破坏后,怎样安然恢复到最后一次正常的状态,使得数据的损失达到最小. 我这里以本博客的wordpress数据为例,来讨论并实现 ...

  4. FortiGate恢复出厂

    1.需求 当需要把设备的所有配置删除,可进行恢复出厂操作.恢复出厂后所有配置都将丢失,若一定要恢复出厂设置建议前先备份当前的配置:备份配置操作步骤请参见"系统管理">> ...

  5. linux命令学习之:echo

    echo命令用于在shell中打印shell变量的值,或者直接输出指定的字符串.linux的echo命令,在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的,因此有必要了解下 ...

  6. android和js互相调用

    import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.o ...

  7. Composer 安装以及使用方法

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. Linux 下安装 curl -sS https://getcomposer.org/ ...

  8. make ;makefile; cmake; qmake的区分

    1. make 是用来执行Makefile的.2. Makefile是类unix环境下(比如Linux)的类似于批处理的"脚本"文件.其基本语法是: 目标+依赖+命令,只有在目标文 ...

  9. mysql中如何使用一句话将一个表的数据导入到另一个表中:insert into ...select

    INSERT INTO cdcd2015(`filename`,`xmlfile`,`updatetime`,`isDel`) SELECT `filename`,`xmlfile`,`updatet ...

  10. C#编译时,提示缺少NuGet包

    A--还原Nuget包前,一定要确保你配置了该项目的包源:如果你没有那就找别人要吧. 工具-选项-Nuget包管理器-程序包源 B--配置编译时自动还原缺少的nuget包: 工具-选项-Nuget包管 ...