Skip to content

Commit 1f23f1b

Browse files
authored
Create maximum-number-of-words-found-in-sentences.cpp
1 parent 88e141e commit 1f23f1b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int mostWordsFound(vector<string>& sentences) {
7+
return 1 + accumulate(cbegin(sentences), cend(sentences), 0,
8+
[](int result, const auto &s) {
9+
return max(result, static_cast<int>(count(cbegin(s), cend(s), ' ')));
10+
});
11+
}
12+
};

0 commit comments

Comments
 (0)