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
- Real or Not? NLP with Disaster Tweets
- AI 경진대회
- Baekjoon
- 우분투
- leetcode
- Docker
- 금융문자분석경진대회
- 프로그래머스
- gs25
- programmers
- 백준
- dacon
- 자연어처리
- Git
- 파이썬
- PYTHON
- 코로나19
- ChatGPT
- Kaggle
- hackerrank
- 프로그래머스 파이썬
- 편스토랑 우승상품
- 편스토랑
- ubuntu
- 맥북
- SW Expert Academy
- 더현대서울 맛집
- 데이콘
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1002. Find Common Characters (Python) 본문
728x90
반응형
Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
You may return the answer in any order.
Example 1:
Input: ["bella","label","roller"]
Output: ["e","l","l"]
Example 2:
Input: ["cool","lock","cook"]
Output: ["c","o"]
Note:
- 1 <= A.length <= 100
- 1 <= A[i].length <= 100
- A[i][j] is a lowercase letter
Solution
from collections import Counter
class Solution:
def commonChars(self, A: List[str]) -> List[str]:
compare = collections.Counter(A[0])
for i in range(len(A)):
cnt = collections.Counter(A[i])
compare = compare & cnt
answer = list(compare.elements())
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 500. Keyboard Row (Python) (0) | 2020.09.13 |
---|---|
[leetCode] 811. Subdomain Visit Count (Python) (0) | 2020.09.12 |
[leetCode] 28. Implement strStr() (Python) (0) | 2020.09.10 |
[leetCode] 1337. The K Weakest Rows in a Matrix (Python) (0) | 2020.09.09 |
[leetCode] 1331. Rank Transform of an Array (Python) (0) | 2020.09.08 |
Comments