Re: [閒聊] 每日leetcode
題目
有幾個字串的前綴是目標字串
思路
用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;
}
};
```
--
邊版的小母雞 — fuckchicken
https://i.imgur.com/wglAuYR.jpg


--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.169.39 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736408663.A.728.html
推
01/09 16:43,
11月前
, 1F
01/09 16:43, 1F
討論串 (同標題文章)
完整討論串 (本文為第 1256 之 1554 篇):