[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 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.
思路将所有words, 计数, == 1, append进入ans
Code
class Solution:
def uncommonWord(self, A, B):
words = A.split() +B.split()
ans, d = [], collections.Counter(words)
for k in d.keys():
if d[k] == 1:
ans.append(k)
return ans
[LeetCode] 884. Uncommon Words from Two Sentences_Easy tag: Hash Table的更多相关文章
- [LeetCode] 532. K-diff Pairs in an Array_Easy tag: Hash Table
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in t ...
- [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] 804. Unique Morse Code Words_Easy tag: Hash Table
International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...
- [LeetCode] 1. Two Sum_Easy tag: Hash Table
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- [LeetCode] 383. Ransom Note_Easy tag: Hash Table
Given an arbitrary ransom note string and another string containing letters from all the magazines, ...
- [LeetCode] 697. Degree of an Array_Easy tag: Hash Table
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...
- 【Leetcode_easy】884. Uncommon Words from Two Sentences
problem 884. Uncommon Words from Two Sentences 题意:只要在两个句子中单词出现总次数大于1次即可. 注意掌握istringstream/map/set的使 ...
随机推荐
- 【JavaScript】--- ES6/ES7/ES8
一.async async其实是ES7才有有的关键字,async的意思是异步,顾名思义是有关异步的操作 async用于声明一个函数是异步的. 通常情况下async.await都是跟随promise一起 ...
- db2 backup export
备份命令: db2 backup db test to /db2data/ 监控备份进度: db2 list utilities show detail <-进度 检测备份文件的有效性: db2 ...
- Jexus .Net at System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, System.Int32 port)
环境:Jexus(独立版)+MVC(5.2.3) +Redis+EF(6.0) Application Exception System.Net.Sockets.SocketException Con ...
- 语音识别bug
# 如果消息为200,则表示talker在交互过程中未识别到用户的语音输入,开启人脸验证确认用户是否还在面前(排除噪声的影响) # 确认时间为3秒,3秒都没有人脸,则确认用户不在.确认用户还在,则提醒 ...
- 恢复制作了系统盘的U盘
制作了系统盘的U盘通常容量会变得很小(比如用win32制作的系统盘) 此时在系统安装完成之后就要把U盘恢复,否则就无法正常使用了 步骤: 1.win+r打开程序搜索框,输入cmd打开dos窗口 2.在 ...
- python selenium配置
写该博客时环境 mac 10.14.1 (18B75) python 3.7 pip (不用这个就是了,用pip3) $ pip --version pip 10.0.1 from /Users/wj ...
- haproxy实现会话保持
HAProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.反向代理为什么需要设置cookie 任何一个七层的http负载均衡器,都 ...
- 转:GET和POST两种基本请求方法的区别
原文地址:GET和POST两种基本请求方法的区别 原文如下: GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL ...
- da5_模块
一.模块.包 什么是模块? 模块实质上就是一个python文件,它是用来组织代码的,意思就是说把python代码写到里面,文件名就是模块的名称,test.py test就是模块名称. 什么是包? 包, ...
- day2_jmeter断言
断言就是:检查返回结果,测试是否通过,就是自动帮你校验结果用的 1)添加响应断言 我们模式匹配规格选择包括