原题链接: 6051. 统计是给定字符串前缀的字符串数目
class Solution {
public:
int countPrefixes(vector<string>& words, string s) {
int res=0;
for(int i=0;i<words.size();i++)
{
string tmp=words[i];
int l=0,r=0;
while(l<tmp.size() || r<s.size())
{
if(tmp[l]==s[r])
{
l++;r++;
}
else break;
}
if(l==tmp.size()) res++;
}
return res;
}
};