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. canvas转img,blob相互转换

    摘自:https://www.cnblogs.com/jyuf/p/7251591.html 函数都比较简单,直接看就ok了 /*----------------------------------- ...

  2. source .bashrc 报错:virtualenvwrapper.sh: There was a problem running the initialization hooks.

    在Ubuntu下安装完virtualenv.virtualenvwrapper,然后设置环境文件 .bashrc 接着 source .bashrc,产生错误信息 首先确认了 libpam-mount ...

  3. python正则中如何匹配汉字以及encode(‘utf-8’)和decode(‘utf-8’)的互转

    正则表达式: [\u2E80-\u9FFF]+$ 匹配所有东亚区的语言  [\u4E00-\u9FFF]+$ 匹配简体和繁体  [\u4E00-\u9FA5]+$ 匹配简体  <input ty ...

  4. LNMP web服务的安装

    第1章 安装Nginx 环境: 系统:CentOS6.5 软件:nginx-1.6.3     mysql-5.5.49    php-5.5.32 1.1 Nginx官网 http://nginx. ...

  5. 15JavaScript switch语句

    1.JavaScript switch 语句 使用 switch 语句来选择要执行的多个代码块之一. 语法: switch(n) { case 1: 执行代码块 1 break; case 2: 执行 ...

  6. 使用babel插件集

    1).打开配置文件".babelrc",配置插件集,代码如下: { "presets":["latest"] } 2).安装babel插件集 ...

  7. js 实现内容的展开和收缩

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. 解决webview上移

    //解决webview上移 $(".webView").blur(function() { setTimeout(function() { var scrollHeight = d ...

  9. STM32利用CUBEMX建立自定义HID工程,并且完成64字节的IN,OUT传输功能。

    STM32 Customed HID开发流程 本文介绍的是STM32的cubeMX自定义HID的开发流程 cubeMX配置customed HID模式.更多详细配置壳查看代码CubeMX的配置文件. ...

  10. python写爬虫时的编码问题解决方案

    在使用Python写爬虫的时候,常常会遇到各种令人抓狂的编码错误问题.下面给出一些简单的解决编码错误问题的思路,希望对大家有所帮助. 首先,打开你要爬取的网站,右击查看源码,查看它指定的编码是什么,如 ...