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