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).返回出现次数最多,同时不在禁用列表中的单词.题目保证至少有一个词不在禁用列表中,而且答案唯一. 禁用列表中的单词用小写字母表 ...
随机推荐
- NHibernate 01 [简述]
本节内容: 系列简述 NHibernate是什么? NHibernate好处? 1.系列简述 最近在项目中使用到NHibernate,所以记录下自己学习的内容和步骤. 2.NHibernate是什么? ...
- Bezier曲线原理—动态解释
公式线性公式给定点P0.P1,线性贝兹曲线只是一条两点之间的直线.且其等同于线性插值.这条线由下式给出: 一阶贝赛尔曲线上的由两个点确定 P0 和P1,当t在0--->1区间上递增时,根据此会得 ...
- 高度注意 Map 类集合 K/V 能不能存储 null 值的情况
集合类 Key Value Super 说明 Hashtable 不允许为 null 不允许为 null Dictionary 线程安全 ConcurrentHashMap 不允许为 null 不允许 ...
- 实用且堪称神器的Chrome插件推荐
前言 相信很多人都在使用 Chrome 浏览器,其流畅的浏览体验得到了不少用户的偏爱,但流畅只是一方面, Chrome 最大的优势还是其支持众多强大好用的扩展程序(Extensions).最近为了更好 ...
- 百度地图API秘钥生成步骤
百度API
- 基于jquery的可查询多级select控件(可记录历史选择)
一.功能和使用 公司有功能需求,还要一条代码引入的控件,网上找完全符合的控件比较难,寻找所花的时间还不如自己写一个,所以找个空闲时间自己写了一个 控件功能:1.可手动输入查询,也可点击下拉框查询, ...
- (转)Android短信的发送和接收监听
/**发送与接收的广播**/ String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_AC ...
- sql的一些事件处理
select getdate() select Convert(varchar(10),getdate(),120) yyyy-mm-ddselect Convert(varchar(20),getd ...
- Eclipse git插件使用
1.Eclipse git插件使用 1)配置提交用户名和邮箱 2)在eclipse中选择Show View 搜索git 3)点击clone按钮 选择代码保存路径 4)导入项目 5)git插件功能介绍 ...
- 快速创建yii2 RESTful api的小记
1.复制backend的应用到同级目录,改名叫api 2.然后就是配置项修改,common和api目录下的 common下: bootstrap.php最后添加一行配置 api/config/main ...