当前位置:网站首页>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;
}
};
边栏推荐
- Cas de rectification du CEM rayonné par des équipements électroniques
- &lt; Pytorch series 4 & gt;: Constructing neural network model
- Ngui, floating blood
- VMware install win7 virtual machine
- UGUI
- 使用bat向文件的第一行中写入内容
- Unity字体间距
- Wsarecv: an existing connection was forcefully closed by the remote host
- 金仓数据库KingbaseES中的sys_checksums坏块检测功能
- Ugui picture wall
猜你喜欢

金仓数据库KingbaseES UDP监控工具的使用

微信小程序之点餐系统附源码

Pl/sql compilation check in kingbasees

以银行异业合作为例,浅谈小程序生态的建设

MySQL基础篇常用约束总结上篇

Leetcode 1952. 三除数

Wuenda machine learning course - week 7

白屏时间、首屏时间

Differences between beanfactory and factorybean

Install MySQL version 5.7 or above on windows (install in compressed package)
随机推荐
MD5学习
Where is it safer to open an account for soda ash futures? How much money can you do?
Pyspark case series 4-dataframe output to a single folder solution
Fix the problem that uicollectionview does not reach the bottom security zone
Circuit board made of real gold -- golden finger
Streaming computing knowledge
Leetcode 1995. 统计特殊四元组(暴力枚举)
NFT将改变元宇宙中的数据所有权
MySQL基础篇常用约束总结上篇
Pagoda panel backup and recovery data
電子設備輻射EMC整改案例
微信小程序之点餐系统附源码
【MYSQL】存储过程的使用
Mysql-- index
IPhone 15 forced to use type-C interface
电子设备辐射EMC整改案例
Dotween usage
Data consistency
知识点滴 - 性格分析-四类法
Browser class for getting started with puppeter