2114. Maximum Number of Words Found in Sentences Easy
1/**
2 * [2114] Maximum Number of Words Found in Sentences
3 *
4 * A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
5 * You are given an array of strings sentences, where each sentences[i] represents a single sentence.
6 * Return the maximum number of words that appear in a single sentence.
7 *
8 * Example 1:
9 *
10 * Input: sentences = ["alice and bob love leetcode", "i think so too", <u>"this is great thanks very much"</u>]
11 * Output: 6
12 * Explanation:
13 * - The first sentence, "alice and bob love leetcode", has 5 words in total.
14 * - The second sentence, "i think so too", has 4 words in total.
15 * - The third sentence, "this is great thanks very much", has 6 words in total.
16 * Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.
17 *
18 * Example 2:
19 *
20 * Input: sentences = ["please wait", <u>"continue to fight"</u>, <u>"continue to win"</u>]
21 * Output: 3
22 * Explanation: It is possible that multiple sentences contain the same number of words.
23 * In this example, the second and third sentences (underlined) have the same number of words.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= sentences.length <= 100
29 * 1 <= sentences[i].length <= 100
30 * sentences[i] consists only of lowercase English letters and ' ' only.
31 * sentences[i] does not have leading or trailing spaces.
32 * All the words in sentences[i] are separated by a single space.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/
38// discuss: https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn most_words_found(sentences: Vec<String>) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2114() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.