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. 『C++』Temp_2019_03_14 不同类的循环引用

    #include <iostream> #include <string> #include <regex> using namespace std; //提前声明 ...

  2. PL/SQL 报错:动态执行表不可访问,本会话的自动统计被禁止。 在执行菜单里你可以禁止统计,或在v$session,v$sesstat 和vSstatname表里获得选择权限。

    现象: 第一次用PL/SQL Developer连接数据库,若用sys用户登录并操作则正常,若用普通用户比如haishu登录并创建一个表则报错“动态执行表不可访问,本会话的自动统计被禁止.在执行菜单里 ...

  3. PHP程序员的技术成长规划 第一阶段:基础阶段

    第一阶段:基础阶段(基础PHP程序员) 重点:把LNMP搞熟练(核心是安装配置基本操作)目标:能够完成基本的LNMP系统安装,简单配置维护:能够用PHP源码做基本的简单系统的PHP开发:能够在PHP中 ...

  4. colemak,你用了吗?

    为了输入代码的感觉更好,我学习了colemak键盘布局,这个布局它是在QWERTY的基础上改了10多个键. 开始的三天,感觉非常不好,每按一个键都要思考很长时间,干脆在网上找了个在线打字的网页去练,感 ...

  5. AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

    Traceback (most recent call last): File "linear_regression_eager_api.py", line 15, in < ...

  6. Wtrofms

    一.安装 安装:pip3 install wtforms 二.使用1(登录) from flask import Flask, render_template, request, redirect f ...

  7. Framwork框架-网络客户端的使用

    1.引入头文件 #include "Comm.h" 2.派生自框架基类CProtocolCpMgr class NetManager : public CProtocolCpMgr ...

  8. MFC 程序退出方法

    基於對話框的: 1.PostQuitMessage(0);2.PostMessage(WM_QUIT,0,0);3.ExitProcess(0);注意使用时先释放分配的内存,以免造成内存泄露4.exi ...

  9. makefile中重载与取消隐藏规则示例

    学习<跟我一起写Makefile-陈皓>后一直不懂,如何重载或取消隐藏规则 为了博客版面整洁,何为隐藏规则,Makefile基本规则编写等基础支持请自行百度. 需要声明的是:这些知识可能在 ...

  10. NodeJS设置Header解决跨域问题

    转载: NodeJS设置Header解决跨域问题 app.all('*', function (req, res, next) { res.header('Access-Control-Allow-O ...