819. Most Common Word Easy
1/**
2 * [819] Most Common Word
3 *
4 * Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.
5 * The words in paragraph are case-insensitive and the answer should be returned in lowercase.
6 *
7 * Example 1:
8 *
9 * Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
10 * Output: "ball"
11 * Explanation:
12 * "hit" occurs 3 times, but it is a banned word.
13 * "ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph.
14 * Note that words in the paragraph are not case sensitive,
15 * that punctuation is ignored (even if adjacent to words, such as "ball,"),
16 * and that "hit" isn't the answer even though it occurs more because it is banned.
17 *
18 * Example 2:
19 *
20 * Input: paragraph = "a.", banned = []
21 * Output: "a"
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= paragraph.length <= 1000
27 * paragraph consists of English letters, space ' ', or one of the symbols: "!?',;.".
28 * 0 <= banned.length <= 100
29 * 1 <= banned[i].length <= 10
30 * banned[i] consists of only lowercase English letters.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/most-common-word/
36// discuss: https://leetcode.com/problems/most-common-word/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn most_common_word(paragraph: String, banned: Vec<String>) -> String {
42 String::new()
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_819() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.