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 ...
随机推荐
- SVN命令行使用总结
1.上传项目到SVN服务器上svn import project_dir(本地项目全路径) http://192.168.1.242:8080/svn/IOS/Ben/remote_dir(svn项目 ...
- 玩转ptrace (一)
转自http://www.cnblogs.com/catch/p/3476280.html [本文翻译自这里: http://www.linuxjournal.com/article/6100?pag ...
- ElasticSearch 5.0 简介
参考:http://blog.csdn.net/wzhg0508/article/details/52063676 Elasticsearch 5.0 简介(medcl微信直播实录) 大家好,非常高兴 ...
- #define WIN32_LEAN_AND_MEAN 的作用
今天看了用mysql的库+vc连接数据库,结果我用mfc application向导建立一个project,然后加入#include "mysql.h"(已经设置好了环境),编译出 ...
- TweenMax.allTo
需要多个MC进行相同的缓动.比如下面这个游戏菜单.三个按钮的缓动是相同的,都缓动到同一个x坐标位置.然后同时有缓动出舞台. 如果有TweenLite实现的话,需要 if (is ...
- RAC5——11gR2以后GI进程的变化
参考文档: 11gR2 Clusterware and Grid Home - What You Need to Know (Doc ID 1053147.1)诊断 Grid Infrastructu ...
- postman的Testing examples(测试脚本示例)
测试代码会在发送request并且接收到responses后执行. 1.设置环境变量 postman.setEnvironmentVariable("key", "val ...
- C/C++动态分配连续空间,下标越界导致的free():invalid next size问题
昨天帮导师做的一个程序出了内存泄露的bug(在VS上程序运行一切正常,等return返回后才出错) 而且是程序运行结束后才出现的错误,在退出前一切代码都顺利执行完了,只是return之后出错. 之后我 ...
- Redis在Windows集群中的错误
创建集群: ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:70 ...
- 【Spring学习笔记-MVC-13】Spring MVC之文件上传
作者:ssslinppp 1. 摘要 Spring MVC为文件上传提供了最直接的支持,这种支持是通过即插即用的MultipartResolve实现的.Spring使用Jakarta Co ...