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的更多相关文章

  1. [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 ...

  2. Leetcode819.Most Common Word最常见的单词

    给定一个段落 (paragraph) 和一个禁用单词列表 (banned).返回出现次数最多,同时不在禁用列表中的单词.题目保证至少有一个词不在禁用列表中,而且答案唯一. 禁用列表中的单词用小写字母表 ...

随机推荐

  1. Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

  2. 编程之美Ex1——求二进制中1的个数

    又被阿里机考虐了一次,决定改变策略开始刷题T^T 一个字节(8bit)的无符号整型,求其二进制中的“1”的个数,算法执行效率尽可能高. 最先想到的移位操作,末尾位&00000001,然后右移, ...

  3. Codeforces 954H Path Counting 【DP计数】*

    Codeforces 954H Path Counting LINK 题目大意:给你一棵n层的树,第i层的每个节点有a[i]个儿子节点,然后问你树上的简单路径中长度在1~n*2-2之间的每个有多少条 ...

  4. Windows 10 四月更新,文件夹名称也能区分大小写?

    Windows 向来是不区分文件和文件夹大小写的,但是从 NTFS 开始却又支持区分文件夹大小写.而 Linux/Mac OS 一向都是区分文件和文件夹大小写的. 本文将推荐 Windows 10 四 ...

  5. UITableView 滚动流程性优化

    影响 UITableView 滚动的流畅性的原因 1. 在代理方法中做了过多的计算占用了 UI 线程的时间 2.同上 3.Cell 中 view 的组织复杂   关于第一点,首先要明白 tablevi ...

  6. 《DSP using MATLAB》示例Example6.6

    代码: h = [1, 2, 3, 2, 1]/9; [C, B, A] = dir2fs(h) 运行结果:

  7. 《DSP using MATLAB》示例Example 6.16、6.17

  8. bat命令2

    echo.@.call.pause.rem(小技巧:用::代替rem)是批处理文件最常用的几个命令,我们就从他们开始学起. echo 表示显示此命令后的字符 echo off 表示在此语句后所有运行的 ...

  9. php+ajax+jquery 定时刷新页面数据

    testajax.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  10. BZOJ3261:最大异或和

    浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:https://lydsy.com/JudgeOnline/problem ...