leetcode748
public class Solution
{
public string ShortestCompletingWord(string licensePlate, string[] words)
{
var list = words.OrderBy(x => x.Length);
var pattern = licensePlate.ToLower();
var dic = new Dictionary<char, int>();
foreach (var p in pattern)
{
if (p >= && p <= )
{
if (!dic.ContainsKey(p))
{
dic.Add(p, );
}
else
{
dic[p]++;
}
}
} foreach (var word in list)
{
bool find = true;
var dic2 = new Dictionary<char, int>();
foreach (var p in word)
{
if (!dic2.ContainsKey(p))
{
dic2.Add(p, );
}
else
{
dic2[p]++;
}
} foreach (var d in dic)
{
if (!dic2.ContainsKey(d.Key) || dic2[d.Key] < dic[d.Key])
{
find = false;
break;
}
}
if (find)
{
return word;
}
} return "";
}
}
leetcode748的更多相关文章
- [Swift]LeetCode748. 最短完整词 | Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
随机推荐
- 定时器setTimeout()的传参方法
更具体的代码:http://www.cnblogs.com/3body/p/5416830.html // 由于setTimeout()的延迟执行特性,所以在执行的函数中直接使用外部函数的变量是无法获 ...
- C# 使用ZXing.NET生成一维码、二维码
以上图片是本示例中的实际运行效果,在生活中我们的一维码(也就是条形码).二维码 使用已经非常广泛,那么如何使用c#.net来进行生成一维码(条形码).二维码呢? 使用ZXing来生成是非常方便的选择, ...
- day36 python学习gevent io 多路复用 socketserver *****
---恢复内容开始--- gevent 1.切换+保存状态 2.检测单线程下任务的IO,实现遇到IO自动切换 Gevent 是一个第三方库,可以轻松通过gevent实现并发同步或异步编程,在geven ...
- Selenium(ThoughtWorks公司开发的web自动化测试工具)
Selenium也是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7.8.9).Mozilla Firefox.Mozill ...
- python、java大作战,python测试dubbo接口
很多小伙伴都反映公司要求测dubbo(dubbo是一个java的分布式开源框架)接口,不会写java代码,怎么测,能不能用python来调dubbo接口.当然是可以的了,最近研究了一下,很简单,分享给 ...
- Oracle 存储过程发送邮件
CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT VARCHAR2, ...
- 修改oracle系统参数spfile导致数据库无法启动解决
错误示范: SQL> alter system set nls_date_format='yyyy-mm-dd 24hh:mi:ss' scope=spfile;System altered.我 ...
- Oracle的静默安装 升级和卸载 参考规范
Oracle的静默安装 升级和卸载 参考规范 20180912 V1 一.Oracle的安装 Oracle产品的三种安装方式分别为: 1.图形化(Java向导)安装引导 2.使用应答文件静默安装 3. ...
- opencv中的图像形态学——腐蚀膨胀
腐蚀膨胀是图像形态学比较常见的处理,腐蚀一般可以用来消除噪点,分割出独立的图像元素等. 一般腐蚀操作对二值图进行处理,腐蚀操作如下图,中心位置的像素点是否与周围领域的像素点颜色一样(即是否是白色点,即 ...
- 使用PHP简单操作Memcached
记得一定要先启动Memcached哦! [root@localhost ~]# /usr/bin/memcached -d -l -m -u root -d 守护进程模式(退出终端窗口之后使程序还在运 ...