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 | 31 |
Tags
- 자연어처리
- 편스토랑
- github
- Git
- 캐치카페
- Docker
- 프로그래머스 파이썬
- 데이콘
- 금융문자분석경진대회
- 코로나19
- Baekjoon
- AI 경진대회
- leetcode
- PYTHON
- 더현대서울 맛집
- 프로그래머스
- 우분투
- dacon
- 파이썬
- programmers
- Kaggle
- ChatGPT
- 편스토랑 우승상품
- SW Expert Academy
- ubuntu
- 백준
- hackerrank
- 맥북
- gs25
- 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
'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 |
Comments