problem

819. Most Common Word

solution:

class Solution {
public:
string mostCommonWord(string paragraph, vector<string>& banned) {
unordered_map<string, int> m;
string word = "";
for(int i=; i<paragraph.size(); )
{
string word = "";
while(i<paragraph.size() && isalpha(paragraph[i]))
{
word.push_back(tolower(paragraph[i]));
i++;
}
while(i<paragraph.size() && !isalpha(paragraph[i])) i++;
m[word]++;
}
for(auto x:banned) m[x] = ;
int num = ;
string res = "";
for(auto x:m)
{
if(x.second >num)
{
num = x.second;
res = x.first;
}
}
return res;
}
};

参考

1. Leetcode_easy_819. Most Common Word;

2. Grandyang;

3. Discuss;

【Leetcode_easy】819. Most Common Word的更多相关文章

  1. 【LeetCode】819. Most Common Word 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+统计 日期 题目地址:https://leet ...

  2. 【Leetcode_easy】1071. Greatest Common Divisor of Strings

    problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrin ...

  3. 【Leetcode_easy】748. Shortest Completing Word

    problem 748. Shortest Completing Word 题意: solution1: class Solution { public: string shortestComplet ...

  4. 【SP1812】LCS2 - Longest Common Substring II

    [SP1812]LCS2 - Longest Common Substring II 题面 洛谷 题解 你首先得会做这题. 然后就其实就很简单了, 你在每一个状态\(i\)打一个标记\(f[i]\)表 ...

  5. 【SP1811】LCS - Longest Common Substring

    [SP1811]LCS - Longest Common Substring 题面 洛谷 题解 建好后缀自动机后从初始状态沿着现在的边匹配, 如果失配则跳它的后缀链接,因为你跳后缀链接到达的\(End ...

  6. 【LeetCode】236. Lowest Common Ancestor of a Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  7. LeetCode 819. Most Common Word (最常见的单词)

    Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...

  8. 【Leetcode_easy】720. Longest Word in Dictionary

    problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...

  9. 【leetcode】Maximum Product of Word Lengths

    Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...

随机推荐

  1. mysqlcheck(MyISAM表维护工具)

    mysqlheck [option] db_name [tables] -c --check(检查表) -r  --repair(修复表) -a  --analyze(分析表) -o  --optim ...

  2. 利用Linux自带的logrotate管理日志

    日常运维中,经常要对各类日志进行管理,清理,监控,尤其是因为应用bug,在1小时内就能写几十个G日志,导致磁盘爆满,系统挂掉. nohup.out,access.log,catalina.out 本文 ...

  3. pandas 4

    参考资料:https://mp.weixin.qq.com/s/QnxaOrvlWJn6Dr42Ic1CcQ 1  #只选取housing,loan,contac和poutcometest_data[ ...

  4. django Error: HINT: Add or change a related_name argument to the definition for 'UserProfile.groups' or 'User.groups'.

    # 解决方案: 因自己重新封装user为UserProfile故在 settings中 添加自己的

  5. 十五.DNS子域授权、分离解析、缓存DNS服务器

    1.搭建基本DNS服务器 pc7: 1.1 安装软件包 ]# yum -y install bind-chroot bind bind         //域名服务包 bind-chroot  //提 ...

  6. PHP全栈学习笔记27

    数组概述,类型,声明,遍历,输出,获取数组中最后一个元素,删除重复数组,获取数组中指定元素的键值,排序,将数组中的元素合成字符串. 数组概述,数组是存储,管理和操作一组变量. 数组类型为一维数组,二维 ...

  7. 6.Python3字符串和格式化

    一.字符串 1.字符串表示方法 2.字符串的序号 3.字符串的使用 4.字符串切片 5.字符串的特殊字符 6.字符串操作符 案例:输入对应的数字显示对应的星期 '''weekStr = "星 ...

  8. (转)hadoop 配置文件解释

    借鉴:https://blog.csdn.net/wangming520liwei/article/details/78923216 Hadoop 参数配置 详解 一.常用端口 组件 节点 默认端口 ...

  9. POI2010 Bridges

    好题\(Q\omega Q\) 我们考虑这个东西要求最大值最小,显然一眼二分答案对吧. 问题在于如何\(check\),我们二分答案之后把问题转换成了混合图如何求欧拉回路. 考虑欧拉回路的性质,每一个 ...

  10. elasticsearch bootstrap.memory_lock

    检查bootstrap.memory_lock设置是否生效 get http://10.127.0.1:9200/_nodes?filter_path=**.mlockall 响应: { " ...