https://leetcode.com/problems/is-subsequence/description/
解题思路:
- 判断s和t的字符是否相等
class Solution {
public boolean isSubsequence(String s, String t) {
int sLen = s.length(), tLen = t.length(), sIndex = 0;
for(int i = 0; i < tLen && sIndex < sLen; i++){
if(t.charAt(i) == s.charAt(sIndex)){
sIndex++;
}
}
return sIndex == sLen;
}
}
网友评论