2185_CountingWordsWithaGivenPrefix - a920604a/leetcode GitHub Wiki
class Solution {
public:
int prefixCount(vector<string>& words, string pref) {
int n = pref.size(), count = 0;
for(string word:words){
int i=0;
for(char c:word){
if(c!=pref[i]) break;
else i++;
}
if(i==n) count++;
}
return count;
}
};
- time complexity
O(n+m)
- space complexity
O(1)