Created
June 26, 2014 14:24
-
-
Save bitcpf/e42630e11005bf25c241 to your computer and use it in GitHub Desktop.
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
/* | |
* Created by bitcpf | |
*/ | |
package cc150_1_8; | |
public class StringRotation { | |
public static boolean isSubstring(String s1, String s2){ | |
String temp = s1+s1; | |
char[] temp_char = temp.toCharArray(); | |
char[] s2_char = s2.toCharArray(); | |
int i = 0; | |
int j = 0; | |
int count = 0; | |
while(i < temp_char.length - s2_char.length){ | |
if(temp_char[i] == s2_char[0]){ | |
j = 0; | |
while(j < s2_char.length){ | |
if(s2_char[j] == temp_char[i+j]){ | |
count ++; | |
} | |
else{ | |
break; | |
} | |
j ++; | |
} | |
} | |
i ++;; | |
if(count == s2.length()){ | |
return true; | |
} | |
} | |
return false; | |
} | |
public static void main(String[] args){ | |
String s1 = "waterbottle"; | |
String s2 = "erbottlewat"; | |
System.out.println(s1); | |
System.out.println(s2); | |
System.out.println(isSubstring(s1,s2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment