题解 | #特工的密码#
特工的密码
https://www.nowcoder.com/practice/bcdfed09de534aea92b24c73699dba5c
所用语言
Java
所用知识
字符串
解题思路
从左到右开始遍历,如果字符相同,把s的索引右移一位,最后判断索引与s的长度即可
完整代码
public boolean isSubsequence (String s, String t) {
// write code here
int index=0;
for(int i=0;i<t.length();i++){
char tch=t.charAt(i),sch=s.charAt(index);
if(tch==sch) index++;
if(index==s.length()) return true;
}
return true;
}
#字符串字符匹配#