给定字符串 s 和 t ,判断 s 是否为 t 的子序列。
字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"
是"abcde"
的一个子序列,而"aec"
不是)。
class Solution {
public boolean isSubsequence(String s, String t) {
if(s.length()>t.length()) return false;
int a=-1;
for (int i = 0; i <s.length() ; i++) {
int j;
for (j = i; j < t.length(); j++) {
if (s.charAt(i) == t.charAt(j)) {
if(a>=j) continue;
a=j;
break;
}
}
if (j ==t.length()) return false;
}
return true;
}
}