[leetcode-884-Uncommon Words from Two Sentences]
We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word consists only of lowercase letters.)
A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.
Return a list of all uncommon words.
You may return the list in any order.
Example 1:
Input: A = "this apple is sweet", B = "this apple is sour"
Output: ["sweet","sour"]
Example 2:
Input: A = "apple apple", B = "banana"
Output: ["banana"]
Note:
0 <= A.length <= 2000 <= B.length <= 200AandBboth contain only spaces and lowercase letters.
思路:
直接利用stringstream 分割处单词来用map统计一下即可。
vector<string> uncommonFromSentences(string A, string B)
{
vector<string>wordA;
stringstream ss(A + " " + B);
string t;
while(ss>>t){wordA.push_back(t);}
map<string,int>mp;
for(auto t : wordA){mp[t]++;}
vector<string>ret;
for(auto it = mp.begin(); it != mp.end(); it++)
{
if(it->second ==)ret.push_back(it->first);
}
return ret;
}
[leetcode-884-Uncommon Words from Two Sentences]的更多相关文章
- [LeetCode] 884. Uncommon Words from Two Sentences 两个句子中不相同的单词
		
We are given two sentences A and B. (A sentence is a string of space separated words. Each word co ...
 - LeetCode 884 Uncommon Words from Two Sentences 解题报告
		
题目要求 We are given two sentences A and B. (A sentence is a string of space separated words. Each wo ...
 - LeetCode 884. Uncommon Words from Two Sentences (两句话中的不常见单词)
		
题目标签:HashMap 题目给了我们两个句子,让我们找出不常见单词,只出现过一次的单词就是不常见单词. 把A 和 B 里的word 都存入 map,记录它们出现的次数.之后遍历map,把只出现过一次 ...
 - 【Leetcode_easy】884. Uncommon Words from Two Sentences
		
problem 884. Uncommon Words from Two Sentences 题意:只要在两个句子中单词出现总次数大于1次即可. 注意掌握istringstream/map/set的使 ...
 - 【LeetCode】884. Uncommon Words from Two Sentences 解题报告(Python)
		
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计 日期 题目地址:https://leetc ...
 - [LeetCode&Python] Problem 884. Uncommon Words from Two Sentences
		
We are given two sentences A and B. (A sentence is a string of space separated words. Each word co ...
 - [LeetCode] 884. Uncommon Words from Two Sentences_Easy tag: Hash Table
		
We are given two sentences A and B. (A sentence is a string of space separated words. Each word co ...
 - LeetCode.884-两句话中不常见的单词(Uncommon Words from Two Sentences)
		
这是悦乐书的第338次更新,第362篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第207题(顺位题号是884).我们给出了两个句子A和B.(一个句子是一串空格分隔的单词 ...
 - C#LeetCode刷题之#884-两句话中的不常见单词(Uncommon Words from Two Sentences)
		
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3816 访问. 给定两个句子 A 和 B . (句子是一串由空格分 ...
 - [Swift]LeetCode884. 两句话中的不常见单词 | Uncommon Words from Two Sentences
		
We are given two sentences A and B. (A sentence is a string of space separated words. Each word co ...
 
随机推荐
- 公司内网静态IP,外网无线动态IP 同时上网,不必再切换网卡啦 route 命令给你搞定。
			
一: 公司内网:192.168.55.101 255.255.255.0 192.168.55.1 网关 外网:192.168.20.101 255.255.255.0 192.16 ...
 - 网页静态化解决方案-Freemarker
			
1.1 技术简介与使用 1.1.1 简介 为什么使用: 1. 减轻数据库的访问压力,静态化比较适合大规模且相对变化不太频繁的数据: 2. 有利于SEO(搜索引擎优化); 纯的HTML ...
 - 【css】 如何修改select的样式
			
select { /*清除select默认样式*/ appearance:none; -moz-appearance:none; -webkit-appearance:none; -ms-appear ...
 - A - Chess Placing CodeForces - 985A
			
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted ...
 - iOS 11.4.1 正式版越狱
			
在 2018 年 Electra 最新能支持到 11.3.1 越狱,很长的一段时间 11.4 只能支持 Beta 版本,临近春节给了我们一个大礼物,终于支持 iOS 11.4-11.4.1,目前 iO ...
 - Redis学习笔记(二)
			
解读Retwis官网例子 Redis需要考虑需要哪些keys以及对应的value使用合适的数据类型进行存储.在retwis例子中,我们需要users,user的粉丝列表, user的关注用户列表等等. ...
 - colemak,你用了吗?
			
为了输入代码的感觉更好,我学习了colemak键盘布局,这个布局它是在QWERTY的基础上改了10多个键. 开始的三天,感觉非常不好,每按一个键都要思考很长时间,干脆在网上找了个在线打字的网页去练,感 ...
 - 面试被问到SPI总结
			
SPI驱动框架 枚举过程 drivers/spi/spi.c: spi_register_board_info /* 对于每一个spi_master,调用spi_match_master_to_boa ...
 - 触摸屏之linux3.4.2安装tslib
			
1. 写好触摸屏驱动后,安装tslib 1.1 tar xzf tslib-1.4.tar.gz 1.2 cd tslib 1.3 修改编译器版本号或者内核版本号,使它们一致.不然会出错,显示sele ...
 - upload-labs19记录
			
upload-labs19记录 本次做题为白盒,因为只是fuzz的话并不能学到什么,所以从漏洞源下手. 前端校验 Pass1 源码 function checkFile() { var file = ...