leetcode720
public class Solution
{
public string LongestWord(string[] words)
{
var maxlist = new List<string>(); var dic = new Dictionary<string, string>();
Queue<string> Q = new Queue<string>();
var maxstr = ""; foreach (var word in words)
{
var temp = word;
if (!dic.ContainsKey(temp))
{
dic.Add(temp, temp.Substring(, temp.Length - ));
}
}
var list = dic.OrderByDescending(x => x.Key.Length).ToList(); foreach (var l in list)
{
var cur = l.Key;
if (cur.Length < maxstr.Length)
{
continue;
} Q.Enqueue(cur);
var len = cur.Length;
while (Q.Any())
{
len--;
var temp = Q.Dequeue();
var subtemp = temp.Substring(, temp.Length - );
if (dic.ContainsKey(subtemp))
{
Q.Enqueue(subtemp);
}
} if (len == )
{
maxlist.Add(cur);
maxstr = cur;
}
} var result = maxlist.OrderBy(x => x).ToList().FirstOrDefault();
return result;
}
}
leetcode720的更多相关文章
- [Swift]LeetCode720. 词典中最长的单词 | Longest Word in Dictionary
Given a list of strings words representing an English Dictionary, find the longest word in words tha ...
- Leetcode720.Longest Word in Dictionary词典中最长的单词
给出一个字符串数组words组成的一本英语词典.从中找出最长的一个单词,该单词是由words词典中其他单词逐步添加一个字母组成.若其中有多个可行的答案,则返回答案中字典序最小的单词. 若无答案,则返回 ...
随机推荐
- cocos studio pageview看不到indicator指示点
发现如果在cocos studio里操作给PageView创建页面元素时,即使setIndicatorEnabled为true也看到下方的指示点,必须调用addWidgetToPage或者insert ...
- Android中的关于MDM中的几个方法举例
Android中的关于MDM中的几个方法举例 首先介绍一下MDM是什么的缩写,MDM是什么? MDM 是 (Mobile Device Management )的缩写,中文翻译过来就是移动设备管理.随 ...
- Ubuntu终端远程连接linux服务器
SSH是一个远程接入软件,可以让你想坐在计算机前面一样操作计算机.SSH使用加密方式传输数据,是一种非常安全的工作方式 步骤如下: 前提:如果没有安装ssh的话请 sudo apt-get inst ...
- a链接嵌套无效,嵌套链接最优解决办法
<a>不支持嵌套.例如: <a href="#1">11111111111<a href="#2">22222222222& ...
- Django(一):从socket到MVC
一.socket的http套路 web应用本质上是一个socket服务端,用户的浏览器是一个socket客户端.socket处在应用层与传输层之间,是操作系统中I/O系统的延伸部分(接口),负责系统进 ...
- Appium+python (3) 异常处理
有时候定位时会发现无法定位到具体的元素,右侧元素定位处只告诉你这是一个网页视图: 点击里面的具体元素是无法选中的,船长的做法是回到App里点一下元素,再返回要定位的页面,重新点一下Device Scr ...
- PHP获取客户端的IP、地理信息、浏览器、本地真实IP
<?php header("Content-type:text/html;charset=utf-8"); // 作用获取客户端的ip.地理信息.浏览器.本地真实IP cla ...
- Python 运行其他程序
10.4 运行其他程序 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程, ...
- 记录一些WPF常用样式方便以后复用(二)(Button、CheckBox、输入账号密码框)(转)
Button (一) <Style x:Key="ButtonSaveStyle" TargetType="{x:Type Button}"> &l ...
- Oracle11g的服务
成功安装Oracle 11g数据库后,你会发现自己电脑运行速度会变慢,配置较低的电脑甚至出现非常卡的状况,通过禁止非必须开启的Oracle服务可以提升电脑的运行速度.那么,具体该怎么做呢.按照win7 ...