본문 바로가기
코딩테스트

[ LeetCode ] 819번 Most Common Word

by 코뮤(commu) 2021. 4. 18.
728x90
반응형

leetcode.com/problems/most-common-word/

 

Most Common Word - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

 

 

 

 

 

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
반응형