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. 最短路 poj1125

    输入一个n表示有n个点,接下来n行,每行(假设是u)第一个数字m表示有m对数字(每一对两个数字v,w,表示u到v的时间w),后面接m对数字.找一个起点,它到其他点所花费的时间(求起点到其他点距离的最大 ...

  2. Trigger,Cursor

    USE [Demo]GO /****** Object: StoredProcedure [dbo].[p_couser_Student] Script Date: 02/24/2014 20:43: ...

  3. jasper打印实例2 ----通过文件字节流获得PDF格式图片

    public class IspReportUtil { public static String exportReportToByte(CommonReportHandler handler)thr ...

  4. echarts横向柱状图如果想打开网址

    代码: var data = eval(data); var xList = new Array(); var yList = new Array(); var urlList = new Array ...

  5. 数据库中where与having区别

    having 和where 都是用来筛选用的 having 是筛选组 而where是筛选记录 他们有各自的区别 1>当分组筛选的时候 用having 2>其它情况用where------- ...

  6. 一、MySQL的连接建立与权限

    一.MySQL的连接建立与权限 写这些的目的一是记录下工作这几年所学,算是成长脚印吧.二是复习一遍,也给自己当笔记看,通篇观点都属于个人理解较多.读者观看的时候也需要自己判断下是否正确,另外,记下一段 ...

  7. 10.Mysql索引

    10.索引的设计和使用10.1 索引概述BTREE索引:Mysql(MyIASM和Innodb)默认的索引类型.前缀索引:对索引字段的前N个字符创建索引.N的最大取值和存储引擎有关,MyIASM支持最 ...

  8. js的面向对象

    JavaScript不区分类和实例的概念,而是通过原型(prototype)来实现面向对象编程. 原型是指当我们想要创建xiaoming这个具体的学生时,我们并没有一个Student类型可用 var ...

  9. 肤色检测一例-使用rgb颜色模型

    代码: /* 输入:rgb图像 输出:与输入图像尺寸相同的灰度图,若rgb图中某像素检测为肤色,则灰度图中对应像素为255,否则为0 */ void SkinRGB( Mat &rgb,Mat ...

  10. 去掉easyui datagrid内部虚线的方式。

    去掉easyui        datagrid内部虚线的方式.easyui datagrid的样式是统一写在样式文件中的,如果想要统一替换可以找对应的datagird样式文件中的以下部分.如果想要改 ...