Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 캐치카페
- 프로그래머스 파이썬
- 자연어처리
- SW Expert Academy
- github
- Docker
- 백준
- 데이콘
- 금융문자분석경진대회
- programmers
- ubuntu
- leetcode
- Kaggle
- 우분투
- Git
- hackerrank
- 프로그래머스
- 더현대서울 맛집
- ChatGPT
- gs25
- 파이썬
- PYTHON
- 편스토랑
- dacon
- Baekjoon
- 코로나19
- AI 경진대회
- Real or Not? NLP with Disaster Tweets
- 맥북
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 884. Uncommon Words from Two Sentences (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 884. Uncommon Words from Two Sentences (Python)
솜씨좋은장씨 2020. 7. 31. 21:24728x90
반응형

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 and B both contain only spaces and lowercase letters.
Solution
from collections import Counter
class Solution:
def uncommonFromSentences(self, A: str, B: str) -> List[str]:
array = A.split(" ") + B.split(" ")
cnt = list(Counter(array).items())
answer = [item[0] for item in cnt if item[1] == 1]
return answer



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 434. Number of Segments in a String (Python) (0) | 2020.08.02 |
---|---|
[leetCode] 1528. Shuffle String (Python) (0) | 2020.08.02 |
[leetCode] 349. Intersection of Two Arrays (Python) (1) | 2020.07.30 |
[leetCode] 1185. Day of the Week (Python) (0) | 2020.07.29 |
[leetCode] 260. Single Number III (Python) (0) | 2020.07.29 |