Lecture Notes on 23 Jul 2013 // characters of s2 are in the same order in s1 public static boolean doesContain (String s1, String s2) { int startIdx = 0; for (int i = 0; i < s2.length(); i++) { if (startIdx >= s2.length()) return false; char ch = s2.charAt(i); int index = s1.indexOf(ch, startIdx); if (index == -1) return false; startIdx = index + 1; } return true; } // characters of s2 are not in the same order in s1 public static boolean doesContain (String s1, String s2) { if (s2.length() > s1.length()) return false; for (int i = 0; i < s2.length(); i++) { char ch = s2.charAt(i); int index = s1.indexOf(ch); if (index == -1) return false; s1 = s1.replace(ch, ''); } return true; }