第二题一样 ,leetcode原题,不知道为啥leetcode能通过,这边60还是80忘记了 // leetcode 判断 是否子序列 public boolean isSubsequence(String s, String l) { if("".equals(s)){ return true; } char[] sc = s.toCharArray(); char[] lc = l.toCharArray(); int left = 0; for (int i = 0; i < lc.length; i++) { if (lc[i] == sc[left]) { left++; } if (left == sc.length) { return true; } } return false; } // 这边获取索引 public int isSubsequence(String s, String l) { if("".equals(s)){ return 0; } char[] sc = s.toCharArray(); char[] lc = l.toCharArray(); int left = 0; for (int i = 0; i < lc.length; i++) { if (lc[i] == sc[left]) { left++; } if (left == sc.length) { return i; } } return -1; }