Skip to content

Commit 7d257e8

Browse files
committed
Add solution #2114
1 parent ab57d30 commit 7d257e8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
2011|[Final Value of Variable After Performing Operations](./2011-final-value-of-variable-after-performing-operations.js)|Easy|
228228
2016|[Maximum Difference Between Increasing Elements](./2016-maximum-difference-between-increasing-elements.js)|Easy|
229229
2047|[Number of Valid Words in a Sentence](./2047-number-of-valid-words-in-a-sentence.js)|Easy|
230+
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
230231

231232
## License
232233

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 2114. Maximum Number of Words Found in Sentences
3+
* https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/
4+
* Difficulty: Easy
5+
*
6+
* A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
7+
*
8+
* You are given an array of strings sentences, where each sentences[i] represents a single sentence.
9+
*
10+
* Return the maximum number of words that appear in a single sentence.
11+
*/
12+
13+
/**
14+
* @param {string[]} sentences
15+
* @return {number}
16+
*/
17+
var mostWordsFound = function(sentences) {
18+
return sentences.reduce((max, str) => Math.max(max, str.split(/\s+/).length), 0);
19+
};

0 commit comments

Comments
 (0)