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. Spring Cloud 功能使用的层面组件(一)

    来源:赤峰seo 实际上,Spring Cloud 是一个全家桶式的技术栈,它包含了很多组件.本文先从最核心的几个组件,也就是 Eureka.Ribbon.Feign.Hystrix.Zuul 入手 ...

  2. Vue获取后端数据 渲染页面后跳转

    主页面 <template> <div> <ul v-for="item in courseList"> <router-link :to ...

  3. jquery仿排列顺序,变换颜色更换class

    ps:箭头是字体图标,需要的可以去阿里字体下载,也可自己替换图片 点击之后的 代码部分 <ul class="Ep_sxxz"> <span class=&quo ...

  4. [Angular] Show a Loading Indicator for Lazy Routes in Angular

    We can easily code split and lazy load a route in Angular. However when the user then clicks that la ...

  5. centos svn的安装和配置

    1.安装svn yum -y install subversion 2.配置 mkdir /home/svn/admin/test mkdir /home/svn/svnrepos svnadmin ...

  6. php数据类型之 NULL类型

    空在英文里面表示是null,它是代表没有.空(null)不是false,不是0,也不是空格. [重点]知道null产生的三种情况,学习empty 和 isset两个函数的区别.大理石平台怎么样 主要有 ...

  7. neo4j查询语句

    一:查询 比较操作: = <> < > <= >= 布尔操作: AND OR NOT XOR 1.把节点的前两个字为"提示"的节点去除" ...

  8. Elasticsearch 监控

    导语 Elasticsearch(文中简称ES)是分布式全文搜索引擎,产品提供高可用.易扩展以及近实时的搜索能力,广泛应用于数据存储.搜索和实时分析.很多服务的可用性对ES重度依赖.因此,保障ES自身 ...

  9. jQuery相关方法10

    一.链式编程的原理 <script> //构造函数 function Person(age){ this.age=age; this.sayHi=function(txt){ if(txt ...

  10. CSS3 backface-visibility 不面向屏幕是否可见

    backface-visibility 属性定义当元素不面向屏幕时是否可见. 如果在旋转元素不希望看到其背面时,该属性很有用. backface-visibility: visible|hidden; ...