【Leetcode_easy】819. Most Common Word
problem
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的更多相关文章
- 【LeetCode】819. Most Common Word 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+统计 日期 题目地址:https://leet ...
- 【Leetcode_easy】1071. Greatest Common Divisor of Strings
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrin ...
- 【Leetcode_easy】748. Shortest Completing Word
problem 748. Shortest Completing Word 题意: solution1: class Solution { public: string shortestComplet ...
- 【SP1812】LCS2 - Longest Common Substring II
[SP1812]LCS2 - Longest Common Substring II 题面 洛谷 题解 你首先得会做这题. 然后就其实就很简单了, 你在每一个状态\(i\)打一个标记\(f[i]\)表 ...
- 【SP1811】LCS - Longest Common Substring
[SP1811]LCS - Longest Common Substring 题面 洛谷 题解 建好后缀自动机后从初始状态沿着现在的边匹配, 如果失配则跳它的后缀链接,因为你跳后缀链接到达的\(End ...
- 【LeetCode】236. Lowest Common Ancestor of a Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 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 ...
- 【Leetcode_easy】720. Longest Word in Dictionary
problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...
- 【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 ...
随机推荐
- 利用Linux自带的logrotate管理日志
日常运维中,经常要对各类日志进行管理,清理,监控,尤其是因为应用bug,在1小时内就能写几十个G日志,导致磁盘爆满,系统挂掉. nohup.out,access.log,catalina.out 本文 ...
- HttpURLConnection getInputStream 400异常的解决
判断getResponseCode,当返回不是HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED, HttpURLConnection. ...
- Redis学习之一--基础知识
一.定义 REmote DIctionary Server(Redis) 是一个以字典结构存储数据的key-value存储系统:使用ANSI C语言编写.遵守BSD协议.支持网络.可基于内存亦可持久化 ...
- 「CF375E」Red and Black Tree「树形DP」
题意 给定一个结点颜色红或黑的树,问最少进行多少次交换黑.红结点使得每个红结点离最近的黑结点距离\(\leq x\). \(1\leq n \leq 500, 1 \leq x \leq 10^9\) ...
- python ros 四元数转欧拉角
#! /usr/bin/python import PyKDL import rospy from sensor_msgs.msg import Imu from nav_msgs.msg impor ...
- vue中class用法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- win7下如何根据端口号杀掉进程
点击windows左下窗口图标按钮. 输入cmd 输入netstat -ano后回车. 左边箭头指向端口号,右边箭头指向为这个端口号对应的进程号pid,我们记下pid号 我们以2001 ...
- 【转】Python基础-字符串
原文地址http://blog.chinaunix.net/uid-21169302-id-446256.html Python-String-Function 字符串中字符大小写的变换: * S.l ...
- web-msg-sender的https支持改造
用的是nginx代理转发443到2120端口实现,官方说workman原生支持,没有实现(现象是 访问 htttps://域名:2120/ 超时,不知道是服务器问题还是什么) 后转为用nginx代理转 ...
- XGBoost、LightGBM、Catboost总结
sklearn集成方法 bagging 常见变体(按照样本采样方式的不同划分) Pasting:直接从样本集里随机抽取的到训练样本子集 Bagging:自助采样(有放回的抽样)得到训练子集 Rando ...