当前位置:网站首页>Leetcode 1961. Check whether the string is an array prefix
Leetcode 1961. Check whether the string is an array prefix
2022-06-11 10:31:00 【I'm not xiaohaiwa~~~~】

Give you a string s And an array of strings words , Please judge s Is it words Of Prefix string .
character string s To be words Of Prefix string , Need to meet :s Can be words In front of k(k by Positive numbers ) Strings are concatenated in order to get , And k No more than words.length .
If s yes words Of Prefix string , return true ; otherwise , return false .
Example 1:
Input :s = "iloveleetcode", words = ["i","love","leetcode","apples"]
Output :true
explain :
s Can be "i"、"love" and "leetcode" Connected to get .
Example 2:
Input :s = "iloveleetcode", words = ["apples","i","love","leetcode"]
Output :false
explain :
Array prefixes cannot be concatenated to get s .
Tips :
- 1 <= words.length <= 100
- 1 <= words[i].length <= 20
- 1 <= s.length <= 1000
- words[i] and s It's only made up of lowercase letters
Code:
class Solution {
public:
bool isPrefixString(string s, vector<string>& words) {
int size=words.size();
string res;
for(int i=0;i<size;i++)
{
res+=words[i];
if(res.length()>=s.length())
{
if(res==s)
return true;
}
}
return false;
}
};
边栏推荐
- 1. system in Library
- Pl/sql compilation check in kingbasees
- Browser class for getting started with puppeter
- Cadence OrCAD capture design method to avoid misoperation graphic tutorial
- RSA signature issues
- NGUI,飘血
- Puppeter class of puppeter introduction
- 利用PHP开发的一款万能、表白墙系统部分代码片段
- C#入門系列(十一) -- 多維數組
- NewOJ Week 2---BCD
猜你喜欢

Mysql--事务

EMC rectification cases of electronic equipment radiation

吴恩达机器学习课程-第七周

Pl/sql compilation check in kingbasees

Introduction to ZigBee module wireless transmission star topology networking structure

金仓数据库KingbaseES中的sys_checksums坏块检测功能

电子设备辐射EMC整改案例

Mysql-- index

解读USB3.0测试项目

Dynamically render data and carousels
随机推荐
Safety related website recommendations
Where is it safer to open an account for soda ash futures? How much money can you do?
WordPress website backup
MD5学习
Use bat to write to the first line of the file
Cas de rectification du CEM rayonné par des équipements électroniques
NGUI,冷却效果
Série de démarrage C # (XI) - - tableaux multidimensionnels
详述用网络分析仪测量DC-DC和PDN
iPhone 15 被迫用上 Type-C 接口
NFT产品是有生命的
为什么说Web3会是「创作者经济」的游戏规则改变者
Leetcode 1961. 检查字符串是否为数组前缀
Unity字体间距
金仓数据库KingbaseES中的PL/SQL 编译检查
Ngui, backpack drag and drop, and random cloning of picture knowledge points
Leetcode 1952. 三除数
rpc的正确打开方式|读懂Go原生net/rpc包
[Bert]: Calculation of last ave state when training tasks with similar Bert semantics
批量对数据添加噪声并生成新命名标注文件