Skip to content

Commit c407ca1

Browse files
authored
Create counting-words-with-a-given-prefix.cpp
1 parent 9c7cc15 commit c407ca1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n * p)
2+
// Space: O(1)
3+
4+
// string
5+
class Solution {
6+
public:
7+
int prefixCount(vector<string>& words, string pref) {
8+
return count_if(cbegin(words), cend(words),
9+
[&pref](const auto& x) {
10+
return x.compare(0, size(pref), pref) == 0;
11+
});
12+
}
13+
};

0 commit comments

Comments
 (0)