当前位置:网站首页>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;
}
};
边栏推荐
- NFT products are alive
- [Bert]: Calculation of last ave state when training tasks with similar Bert semantics
- rpc的正确打开方式|读懂Go原生net/rpc包
- MySQL transaction
- Excellent test engineer must have 4 safety test methods!
- Wechat applet ordering system with source code
- RSA signature issues
- Ngui, map zoom in and out
- 用真金做的电路板——金手指
- Summary of common constraints in MySQL foundation part I
猜你喜欢

Safety related website recommendations

Detail measurement of DC-DC and PDN with network analyzer

rpc的正确打开方式|读懂Go原生net/rpc包

Preview component packaging graphic tutorial in cadence OrCAD capture schematic design interface

Installing mysql5.7 for Linux

Leetcode 1961. 检查字符串是否为数组前缀

pyspark案例系列4-dataframe输出到单个文件夹的解决方案

Cadence OrCAD capture design method to avoid misoperation graphic tutorial

Mysql--事务

金仓数据KingbaseES 批量创建数据库对象
随机推荐
本人书签常存的地址
Knowledge drop - personality analysis - four types of method
MySQL foundation part common constraints summary part 2
Correct opening method of RPC | understand go native net/rpc package
minIni移植到littlefs
Fix the problem that uicollectionview does not reach the bottom security zone
数字藏品系统开发源码搭建
批量对数据添加噪声并生成新命名标注文件
Safety related website recommendations
Ngui, select gender male and female
Pyramidtnt: TNT with characteristic pyramid structure
Ngui, chat scroll box, UI textlist
选择DC-DC开关电源控制器的实战过程
NGUI,选择性别男女
Detail measurement of DC-DC and PDN with network analyzer
Circuit board made of real gold -- golden finger
Mysql--事务
C#入门系列(十一) -- 多维数组
NFT将改变元宇宙中的数据所有权
Kingbasees create database objects in batch