Re: [闲聊] 每日leetcode

楼主: oin1104 (是oin的说)   2025-01-09 15:44:21
题目
有几个字串的前缀是目标字串
思路
用substr看
py还有一行解 超姆咪
```cpp
class Solution {
public:
int prefixCount(vector<string>& words, string pref)
{
int n = pref.size();
int res = 0;
for(string k : words)
{
if(k.substr(0,n) == pref)res++;
}
return res;
}
};
```

Links booklink

Contact Us: admin [ a t ] ucptt.com