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.
class Solution:
def uncommonFromSentences(self, A, B):
"""
:type A: str
:type B: str
:rtype: List[str]
"""
listA=A.split(' ')
listB=B.split(' ') ans=[] nA=len(listA)
nB=len(listB) for i in range(nA):
ch=listA[i]
if not ch in listB and not ch in (listA[:i]+listA[i+1:]):
ans.append(ch) for j in range(nB):
ch=listB[j]
if not ch in listA and not ch in (listB[:j]+listB[j+1:]):
ans.append(ch) return ans

  

[LeetCode&Python] Problem 884. Uncommon Words from Two Sentences的更多相关文章

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

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

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

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

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

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

  5. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  6. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  7. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

  8. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  9. [LeetCode&Python] Problem 520. Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

随机推荐

  1. Ubuntu 添加,删除ppa

    PPA,英文全称为 Personal Package Archives,即个人软件包档案.是 Ubuntu Launchpad 网站提供的一项源服务,允许个人用户上传软件源代码,通过 Launchpa ...

  2. vs2010的VCVARS32.BAT所在位置

    1. C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat 2. ZC:vs08 和 vs2010 安装好后, ...

  3. PHP使用phpstorm进行断点调试

    1.下载xdebug模块 (https://xdebug.org/) 注意:带"ts"是线程安全的意思,"nts"的他没有标示,也就是说,如果是nts的要下载没 ...

  4. Appium 坑

    1. [Android]click没有反应 https://testerhome.com/topics/9610 在某些手机上有个安全选项,需要在开发者选项->安全设置(允许模拟点击),打开开关

  5. English trip -- VC(情景课)3 A Family

    xu言: 今天,老天很给面子.我在路上的时候基本上没有~然而我也没有带雨具.难道这就是传中的天道酬勤~或者说只要你努力,老天爷会给让路 Talk about the picture 看图说话 Look ...

  6. 3-23 Rspec自动化测试(开始练习)

    闰年程序 leap_year_spec.rb require_relative './leap_year' describe "Leap Year" do it "201 ...

  7. Java基础-面向对象(08)

    面向过程 完成一个需求的步骤:首先是搞清楚我们要做什么,然后在分析怎么做,最后我们再代码体现.一步一步去实现,而具体的每一步都需要我们去实现和操作.这些步骤相互调用和协作,完成我们的需求.面向过程开发 ...

  8. 37mysql 表操作

    创建表 #语法: create table 表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[(宽度) 约束条件], 字段名3 类型[(宽度) 约束条件] ); #注意: 1. 在同一张 ...

  9. OAF页面集成条形码或者二维码

    OAF页面集成条形码 OAF生成条形码 OAF页面集成二维码跟这个类似,生成二维码需要以下jar包,zxing-core.jar, zxing-javase.jar,可自行去maven下载. 代码如下 ...

  10. JavaWeb重定向和转发

    if (user != null && passWord.equals(user.getPassWord())) { // 登录成功 // response.sendRedirect( ...