Last active
August 24, 2019 00:31
-
-
Save gansai/1587a73ed650459b6f0416ab0994ce34 to your computer and use it in GitHub Desktop.
check for string rotation in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IsRotation { | |
public static void main(String[] args) { | |
String a = "ABCD"; | |
String b = "DABC"; | |
System.out.println(isRotation(a,b)); | |
String c = "DCAB"; | |
System.out.println(isRotation(a,c)); | |
} | |
private static boolean isRotation(String a, String b) { | |
if(a.length() == b.length() && (( a + a).indexOf(b) ) != -1){ | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment