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. python 操作 MySQL 即相关问题

    导入pymysql import pymysql # 创建connect()对象 conn = pymysql.connect( host = '127.0.0.1', port = 3306, us ...

  2. 在vscode中进行nodejs服务端代码调试(代码修改自动重启服务端)

    使用到的是nodemon,具体在package.json文件中配置如下: "scripts": { "start": "node ./bin/www& ...

  3. Redis的下载、安装及启动

    一.下载Redis 1. redis 的下载路径 https://pan.baidu.com/s/1tdMzOlcTlFC7Z3a3I_59hQ 提取码:5tgy 二.安装Redis cd到当前解压目 ...

  4. Linux分区格式化

    格式化(format)是指对磁盘或磁盘中的分区(partition)进行初始化的一种操作,这种操作通常会导致现有的磁盘或分区中所有的文件被清除.格式化通常分为低级格式化和高级格式化.如果没有特别指明, ...

  5. linux系列(四):mkdir命令

    1.命令格式: mkdir [选项] 目录名 2.命令功能: 通过 mkdir 命令可以实现在指定位置创建以 DirName(指定的文件名)命名的文件夹或目录.要创建文件夹或目录的用户必须对所创建的文 ...

  6. sql server 发布订阅

    [配置] 一. 发布方 复制 >> 如果有问题 C:\Windows\System32\drivers\etc hosts: 127.0.0.1 ?? 二. 订阅方 订阅方设置结束 三. ...

  7. Homebrew 使用国内镜像

    在国内的网络环境下使用 Homebrew 安装软件的过程中,可能会长时间卡在 Updating Homebrew ... 方法一:按command + c 取消本次更新操作,直接安装软件 方法二:设置 ...

  8. 异步任务神器 和定时任务Celery

    异步任务神器 Celery Celery 在程序的运行过程中,我们经常会碰到一些耗时耗资源的操作,为了避免它们阻塞主程序的运行,我们经常会采用多线程或异步任务.比如,在 Web 开发中,对新用户的注册 ...

  9. CodeForces - 1189E Count Pairs(平方差)

    Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Fi ...

  10. 利用iis创建网站后为什么不能设置主机名

    主机名 主机名就是网站的域名,通俗说就是网站地址(如:www.baidu.com). 设置了主机名,而IIS确不知道主机名对应的地址在哪里. 举个例子,把www.baidu.com做为IIS网站的主机 ...