Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 443 Bytes

File metadata and controls

26 lines (17 loc) · 443 Bytes

Most Common Word

Description

link


Solution

  • See Code

Code

O(nlogn)

class Solution:
    def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
        import re
        ban = set(banned)
        words = re.findall(r'\w+', paragraph.lower())
        return collections.Counter(w for w in words if w not in ban).most_common(1)[0][0]