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