Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 943 Bytes

_819. Most Common Word.md

File metadata and controls

35 lines (24 loc) · 943 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 24, 2024

Last updated : September 24, 2024


Related Topics : Array, Hash Table, String, Counting

Acceptance Rate : 44.39 %


Solutions

Python

class Solution:
    def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
        cnt = Counter([x.lower() for x in re.findall('[A-Za-z]+', paragraph)])
        banned = set(banned)
        output = sorted([x for x in cnt.keys() if x not in banned], key=lambda x: cnt[x])
        return output[-1]