728x90
https://leetcode.com/problems/find-common-characters/
class Solution:
def commonChars(self, words: List[str]) -> List[str]:
result = []
result_dic = {}
for c in words[0]:
if result_dic.get(c) is None:
result_dic[c] = 1
else:
result_dic[c] += 1
for word in words[1:]:
for key, value in result_dic.copy().items():
if word.count(key) == 0:
result_dic.pop(key)
elif word.count(key) < value:
result_dic[key] = word.count(key)
for key, value in result_dic.items():
for i in range(0, value):
result.append(key)
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2671. Frequency Tracker (0) | 2024.02.07 |
---|---|
[Leetcode] 2236. Root Equals Sum of Children (0) | 2024.02.05 |
[Leetcode] 2703. Return Length of Arguments Passed (0) | 2024.02.02 |
[Leetcode] 9. Palindrome Number (0) | 2024.02.02 |
[Leetcode] 2859. Sum of Values at Indices With K Set Bits (0) | 2023.09.17 |