1.s字符串为空时,直接返回true
2.s长度大于t长度时直接返回false
3.i在s里遍历:
j在t里遍历,找到t[j] == s[i]的位置,i j后移
4.如果非子序列那么最后j肯定会找不到溢出,即j > t.length
代码:
class Solution {
public boolean isSubsequence(String s, String t) {
if(s.length() == 0)return true;
if(s.length() > t.length())return false;
int i = 0, j = 0;
while(i < s.length()){
while(j < t.length() && s.charAt(i) != t.charAt(j))j++;
i++;
j++;
}
if(j > t.length())return false;
return true;
}
}



