当前位置:网站首页>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;
}
};
边栏推荐
- 对于跨境电商,更侧重收入的出价策略 —Google SEM
- Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
- 阿里云开发板HaaS510报送设备属性
- 阿里云开发板HaaS510连接物联网平台--HaaS征文
- Introduction to color coding format
- 阿里云开发板HaaS510响应UART串口指令
- Lua tvalue structure
- SystemC simulation scheduling mechanism
- [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)
- Greed issues - Egypt scores
猜你喜欢

When the byte jumps, the Chinese 996 is output in the United States

高考回忆录

Summary of virtual box usage problems

Alibaba cloud development board haas510 parses serial port JSON data and sends attributes

Implementation and debug of process hiding under x64

Alibaba Cloud Development Board haas510 submission Device Properties

浅谈中国程序员为什么要跳槽?

Qt5 plug-in production

Talk about the top 10 classic MySQL errors

简述CGI与FASTCGI区别
随机推荐
Alicloud development board vscode development environment setup
3. Process concealment under the ring ----- continuous concealment and new opening prevention
Use of awlive structures
List of common ACM knowledge points (to be continued)
Now you must know the pointer
Display logs in the database through loganalyzer
阿裏雲開發板HaaS510報送設備屬性
SystemC time
Wait function in SystemC
Behind the unsealing of Shanghai, this group of developers "cloud gathering" built an AI anti epidemic robot
After reading the question, you will point to offer 16 Integer power of numeric value
Implementation of Ackermann function with simulated recursion
Details of bypassing safeseh mechanism by using modules that do not enable safeseh
正点原子STM32F429核心板的插座型号
[MySQL advanced] index classification and index optimization scheme (V)
聊聊MySQL的10大经典错误
测试工程师如何转型测开
Programmer interview golden classic good question / interview question 01.05 Edit once
Démontage et modification de la machine publicitaire - décompression amateur
单总线温度传感器18B20数据上云(阿里云)