← 返回 linkedin 的题目列表Top K Frequent Words in a String
类型:online_judge
Given a long string, return the top K most frequent words. Implement a function top_k_frequent_words(text: str, k: int) -> List[str>, where text is the input string, and k is the number of words to return. You can assume the text contains only letters and spaces. Words in the result should be sorted by frequency in descending order, and alphabetically for words with the same frequency. Provide at least 3 test cases.
Example
Input
the day is sunny the the the sunny is is
4