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:

  1. 0 <= A.length <= 200
  2. 0 <= B.length <= 200
  3. A and B 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]的更多相关文章

  1. [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 ...

  2. 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 ...

  3. LeetCode 884. Uncommon Words from Two Sentences (两句话中的不常见单词)

    题目标签:HashMap 题目给了我们两个句子,让我们找出不常见单词,只出现过一次的单词就是不常见单词. 把A 和 B 里的word 都存入 map,记录它们出现的次数.之后遍历map,把只出现过一次 ...

  4. 【Leetcode_easy】884. Uncommon Words from Two Sentences

    problem 884. Uncommon Words from Two Sentences 题意:只要在两个句子中单词出现总次数大于1次即可. 注意掌握istringstream/map/set的使 ...

  5. 【LeetCode】884. Uncommon Words from Two Sentences 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计 日期 题目地址:https://leetc ...

  6. [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 ...

  7. [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 ...

  8. LeetCode.884-两句话中不常见的单词(Uncommon Words from Two Sentences)

    这是悦乐书的第338次更新,第362篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第207题(顺位题号是884).我们给出了两个句子A和B.(一个句子是一串空格分隔的单词 ...

  9. C#LeetCode刷题之#884-两句话中的不常见单词(Uncommon Words from Two Sentences)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3816 访问. 给定两个句子 A 和 B . (句子是一串由空格分 ...

  10. [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 ...

随机推荐

  1. crashes

    iOS 僵尸对象调试 - 简书 iOS APP审核被拒的解决之道(2.1) - - ITeye博客 iOS应用崩溃日志分析 - CocoaChina 苹果开发中文站 - 最热的iPhone开发社区 最 ...

  2. 获取Linux下的IP地址 java代码

    /** * 获取Linux下的IP地址 * * @return IP地址 * @throws SocketException */ public static String getLinuxLocal ...

  3. T-SQL查询:WITH AS 递归计算某部门的所有上级机构或下级机构

    drop table #Area; CREATE TABLE #Area ( id INT NOT NULL, city_name NVARCHAR(100) NOT NULL, parent_id ...

  4. eclipse 打开一个新工程的基本设置

    1.代码自动提示 Window -> Preferences -> Java -> Editor -> Content Assist -> Auto Activation ...

  5. python class用法

    创建一个名为 Restaurant 的类,其方法 __init__() 设置两个属性: name 和 type  1.创建一个名为 describe_restaurant() 的方法,前者打印前述两项 ...

  6. 偏前端 + rsa加解密 + jsencrypt.min.js--(新增超长字符分段加解密)

    <html> <head> <title>JavaScript RSA Encryption</title> <meta charset=&quo ...

  7. 由object元素引出的事件注册问题和层级显示问题

    项目有一个双击监控视频全屏的需求,视频播放使用的是IE下的ActiveX控件,web页面中使用HTML嵌入对象元素object.预期方案如下: 1.在开发ActiveX控件时加入双击事件. 2.通过d ...

  8. hadoop docker集群搭建

    获取镜像 #本机内 docker pull ubuntu:16.04 编排镜像 启动一个容器 #本机内 docker run -i -t --name master ubuntu:16.04 在容器内 ...

  9. 重学Veriliog(2)——高级编程语句

    1.判断 1.1 if ... else ... 有优先级 在组合逻辑电路中,需要避免产生Latch(避免结构不完整) Latch容易引起竞争冒险,同时静态时序分析工具也不好分析穿过Latch的路径? ...

  10. 20155316 2016-2017-2 《Java程序设计》第3周学习总结

    教材学习内容总结 类:创建类.使用类 基本类类型与类类型 数组 封装的概念 重载 类语法 static成员 教材学习中的问题和解决过程 1.既然数组在JAVA中就是对象,那么int[] 是否是一个类呢 ...