[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 <= 200
0 <= B.length <= 200
A
andB
both 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 ...
随机推荐
- NodeJ node.js基础
因为是Node服务器端的,怎样实现前台和后台请求以及回应 URL(由什么组成的 ),传输的内容:表单数据 文件数据 [图片.压缩包.各种后缀文件] URL的组成 URL由三部分组成: 协议类型 , ...
- Font Awesome图标字体
1.unicode unicode是字体在网页端最原始的应用方式,特点是: 兼容性最好,支持ie6+,及所有现代浏览器. 支持按字体的方式去动态调整图标大小,颜色等等. 但是因为是字体,所以不支持多色 ...
- vue--slot插槽的使用方式
slot 插槽可以在子组件中为父组件要传递的标签占位置 能够有效的减少代码冗余 使代码更加有逼格 第一个例子 <body> <div class="app"& ...
- 【Zookeeper】编程实战之Zookeeper分布式锁实现秒杀
1. Zookeeper简述 我们要了解一样技术,首先应该要到它的官网,因为官网的信息一般都是最准确的,如下图是Zookeeper官网对它的介绍. 从官网的介绍中,可以总结出,Zookeeper是一个 ...
- Java HashMap 源代码分析
Java HashMap jdk 1.8 Java8相对于java7来说HashMap变化比较大,在hash冲突严重的时候java7会退化为链表,Java8会退化为TreeMap 我们先来看一下类图: ...
- JournalNode的作用
NameNode之间共享数据(NFS .Quorum Journal Node(用得多)) 两个NameNode为了数据同步,会通过一组称作JournalNodes的独立进程进行相互通信.当activ ...
- # 20155224 实验四 Android程序设计
20155224 实验四 Android程序设计 任务一 Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for And ...
- Oracle下如何用rman备份到特定的sequence
本文为摘抄,目的为方便日后阅读: http://docs.oracle.com/cd/B12037_01/server.101/b10734/rcmbackp.htm To determine the ...
- 成都Uber优步司机奖励政策(4月14日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- KVM克隆CentOS6虚拟机后无法启动
启动网卡报如下错误: Bringing up interface eth0: Device eth0 does not seem to be present,delaying initializati ...