image.png

解题思路

贪心

基于前一相等字符的索引对比得出当前元素

  1. public boolean isSubsequence(String s,String t){
  2. char[] chars = s.toCharArray();
  3. int index = -1;
  4. for(char temp:chars){
  5. index = t.indexOf(temp, index + 1);
  6. if(index == -1)
  7. return false;
  8. }
  9. return true;
  10. }