2255_CountPrefixesofaGivenString - a920604a/leetcode GitHub Wiki
class Solution {
public:
int countPrefixes(vector<string>& words, string s) {
int count = 0 ;
for(int i=0;i<s.size();++i){
string temp = s.substr(0,i+1);
for(const auto word:words){
if(word == temp) count++;
}
}
return count;
}
};
- time complexity
O(nm)
- space complexity
O(n)