@Test public void testIsRotation() { assertTrue(isRotation("erbottlewat", "waterbottle")); assertFalse(isRotation("erbottlewat", "waterbottel")); }
public static boolean isRotation(String s1, String s2) { int len = s1.length(); if (s2.length() != len) { return false; } char[] charArr1 = s1.toCharArray(); char[] charArr2 = s2.toCharArray(); int j = 0; for (int i = 0; i < len && j < len; i++) { if (charArr1[i] == charArr2[j]) { j++; } } return isSubstring(s1, String.valueOf(Arrays.copyOfRange(charArr2, j, len))); }
PracticeQuestionsCh1 { public static boolean isRotation(String s1, String s2) { int len = s1.length(); if (s2.length() != len) { return false; } char[] charArr1 = s1.toCharArray(); char[] charArr2 = s2.toCharArray(); int j = 0; for (int i = 0; i < len && j < len; i++) { if (charArr1[i] == charArr2[j]) { j++; } } return isSubstring(s1, String.valueOf(Arrays.copyOfRange(charArr2, j, len))); } }
PracticeQuestionsCh1 { public static boolean isRotation(String s1, String s2) { int len = s1.length(); if (s2.length() != len) { return false; } char[] charArr1 = s1.toCharArray(); char[] charArr2 = s2.toCharArray(); int j = 0; for (int i = 0; i < len && j < len; i++) { if (charArr1[i] == charArr2[j]) { j++; } } return isSubstring(s1, String.valueOf(Arrays.copyOfRange(charArr2, j, len))); }  }
PracticeQuestionsCh1 { public static boolean isRotation(String s1, String s2) { int len = s1.length(); if (s2.length() != len) { return false; } char[] charArr1 = s1.toCharArray(); char[] charArr2 = s2.toCharArray(); int j = 0; for (int i = 0; i < len && j < len; i++) { if (charArr1[i] == charArr2[j]) { j++; } } return isSubstring(s1, String.valueOf(Arrays.copyOfRange(charArr2, j, len))); }  static boolean isUnique(String s); static boolean isPermutation(String s1, String s2); static String encodeRepeatedChars(final String str); static void fillIfZero(int[][] matrix); static boolean isRotation(String s1, String s2); }
PracticeQuestionsCh1 { public static boolean isRotation(String s1, String s2) { int len = s1.length(); if (s2.length() != len) { return false; } char[] charArr1 = s1.toCharArray(); char[] charArr2 = s2.toCharArray(); int j = 0; for (int i = 0; i < len && j < len; i++) { if (charArr1[i] == charArr2[j]) { j++; } } return isSubstring(s1, String.valueOf(Arrays.copyOfRange(charArr2, j, len))); }  static boolean isUnique(String s); static boolean isPermutation(String s1, String s2); static String encodeRepeatedChars(final String str); static void fillIfZero(int[][] matrix); static boolean isRotation(String s1, String s2); static final Logger LOGGER; }