leetcode819
public class Solution
{
public string MostCommonWord(string paragraph, string[] banned)
{
//"a, a, a, a, b,b,b,c, c"
paragraph = paragraph.ToLower().Replace("!", " ").Replace("?", " ").Replace("'", " ").Replace(",", " ").Replace(";", " ").Replace(".", " ");
var list = paragraph.Split(' ');
var dic = new Dictionary<string, int>();
foreach (var l in list)
{
var temp = l.Trim();
if (temp.Length == )
{
continue;
}
var filter = banned.Where(x => x == temp).ToList();
if (filter.Count > )
{
continue;
}
if (!dic.ContainsKey(temp))
{
dic.Add(temp, );
}
else
{
dic[temp]++;
}
} var result = dic.OrderByDescending(x => x.Value).ToList().FirstOrDefault();
return result.Key;
}
}
leetcode819的更多相关文章
- [Swift]LeetCode819. 最常见的单词 | Most Common Word
Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...
- Leetcode819.Most Common Word最常见的单词
给定一个段落 (paragraph) 和一个禁用单词列表 (banned).返回出现次数最多,同时不在禁用列表中的单词.题目保证至少有一个词不在禁用列表中,而且答案唯一. 禁用列表中的单词用小写字母表 ...
随机推荐
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
- cannot find lstdc++
centos下编译grpc-java时遇到的问题,google了一下 : sudo yum install libstdc++-static
- Sprint第一个冲刺(第八天)
一.Sprint介绍 完善点餐界面,点击进行跳转. 实验截图: 任务进度: 二.Sprint周期 看板: 燃尽图:
- LG3565 [POI2014]HOT-Hotels
题意 有一个树形结构,每条边的长度相同,任意两个节点可以相互到达.选3个点.两两距离相等.有多少种方案? 1≤n≤5 000 分析 参照小塘空明的题解. 很明显到一个点距离相等的三个点两两之间距离相等 ...
- MVC之前的那点事儿 ---- 系列文章
MVC之前的那点事儿系列,是笔者在2012年初阅读MVC3源码的时候整理的,主要讲述的是从HTTP请求道进入MVCHandler之前的内容,包括了原创,翻译,转载,整理等各类型文章,当然也参考了博客园 ...
- BZOJ2384:[CEOI2014]Match
浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...
- mysql binlog_format row and Statement 比较
两种模式的对比: Statement 优点 历史悠久,技术成熟: 产生的 binlog 文件较小: binlog 中包含了所有数据库修改信息,可以据此来审核数据库的安全等情况: binlog 可以用于 ...
- mac下的virtualbox启动失败处理
不知从哪个版本开始,mac下的virtualbox建立vm以后,启动就提示什么驱动没有加载,google后,解决如下 sudo /Library/Application\ Support/Virtua ...
- Linux之安装软件
1. 下载获得redis-3.0.4.tar.gz后将它放入我们的Linux目录/opt 2. 在SecureCRT界面上点SecureFX图标 在本地窗口中找到要上传的文件 在要上传的文件上点右键 ...
- Struts2操作request、session和application对象
Struts 2提供了多种方式来访问上述的三种对象,归结起来,可以划分为两大类:与Servlet API解耦的访问方式和与Servlet API耦合的访问方式. 与Servlet API解耦的访问方式 ...