728x90
반응형
leetcode.com/problems/most-common-word/
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
#data cleansing
words = [word for word in re.sub('[^\w]',' ',paragraph).lower().split() if word not in banned]
counts = collections.Counter(words)
return counts.most_common(1)[0][0]
728x90
반응형
'Archive > Develop' 카테고리의 다른 글
[ GitHub ] Build Docker Image with Private Repo (0) | 2021.04.24 |
---|---|
[ LeetCode ] 49번 Group Anagrams (0) | 2021.04.19 |
[ LeetCode ] 937번 Reorder Data in Log Files 풀이 (0) | 2021.04.16 |
[ LeetCode ] 344번 Reverse String (0) | 2021.04.15 |
[ Leetcode ] 125번 Valid Palindrome 풀이 (0) | 2021.04.15 |