判断是否为子序列
public class Demo1 {
public static void main(String[] args) { String s = "abp"; String t = "ahbgdc"; System.out.println(isSubsequence(s,t)); } public static boolean isSubsequence(String s, String t) { int index = -1; for (char c : s.toCharArray()) { index = t.indexOf(c,index+1); System.out.println(index); if (index == -1) { return false; } } return true; }
}