当前位置:网站首页>Leetcode 2185. 统计包含给定前缀的字符串
Leetcode 2185. 统计包含给定前缀的字符串
2022-06-12 13:57:00 【我不是萧海哇~~~~】

给你一个字符串数组 words 和一个字符串 pref 。
返回 words 中以 pref 作为 前缀 的字符串的数目。
字符串 s 的 前缀 就是 s 的任一前导连续字符串。
示例 1:
输入:words = ["pay","attention","practice","attend"], pref = "at"
输出:2
解释:以 "at" 作为前缀的字符串有两个,分别是:"attention" 和 "attend" 。
示例 2:
输入:words = ["leetcode","win","loops","success"], pref = "code"
输出:0
解释:不存在以 "code" 作为前缀的字符串。
提示:
- 1 <= words.length <= 100
- 1 <= words[i].length, pref.length <= 100
- words[i] 和 pref 由小写英文字母组成
Code:
class Solution {
public:
int prefixCount(vector<string>& words, string pref) {
int res=0;
for(int i=0;i<words.size();i++)
{
if(words[i].find(pref)==0)
res++;
}
return res;
}
};
边栏推荐
- 初学者入门阿里云haas510开板式DTU(2.0版本)--510-AS
- 阿里云开发板HaaS510连接物联网平台--HaaS征文
- Relevant knowledge points of cocoapods
- Knowledge of wireless card driver
- Cmake basic tutorial - 01 a-hello-cmake
- Now you must know the pointer
- chapter19 Allocation
- NotePad 常用设置
- [advanced MySQL] evolution of MySQL index data structure (IV)
- 阿里云开发板HaaS510将串口获取数据发送到物联网平台
猜你喜欢

拆改廣告機---業餘解壓

chapter19 Allocation

Possible solutions to problems after CodeBlocks installation

Alicloud development board vscode development environment setup

MySQL 查询 limit 1000,10 和 limit 10 速度一样快吗? 深度分页如何破解

Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
![[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX](/img/90/98faa5856fbc55ff7fda4a3adb3650.png)
[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX

List of common ACM knowledge points (to be continued)

Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)

聊聊MySQL的10大经典错误
随机推荐
What is the default gateway
Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode
Codeforces 1637 F. Towers - thinking, DFS
Axi4 increase burst / wrap burst/ fix burst and narrow transfer
Backtracking: Prime Rings
Byte order data read / write
Codeforces 1638 A. reverse - simple thinking
Formal analysis of Woo Lam protocol with scyther tool
[semidrive source code analysis] [x9 chip startup process] 26 - LK of R5 safetyos_ INIT_ LEVEL_ Target phase code flow analysis (TP drvier, audio server initialization)
Codeforces Round #798 (Div. 2)(A~D)
Create a small root heap and judge the node relationship (also.C\u str() substr(),atoi(),string. Use of find())
Codeforces 1637 A. sorting parts - simple thinking
Use of pytorch (to be supplemented)
Use of awlive structures
280 weeks /2171 Take out the least number of magic beans
Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform
My resume.
Fourteen week assignment
Void pointer (void*) usage
Shell脚本到底是什么高大上的技术吗?