Created
April 23, 2012 13:14
-
-
Save zac-xin/2470846 to your computer and use it in GitHub Desktop.
1.8
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
/* | |
* Assume you have a method isSubstring which checks if one word is a substring of | |
* another. | |
* Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using | |
* only one call to isSubstring (i e , “waterbottle” is a rotation of “erbottlewat”) | |
*/ | |
public class SubString { | |
public static void main(String args[]){ | |
String s1 = "waterbottle"; | |
String s2 = "erbottlewat"; | |
System.out.println(isSubString(s1, s2)); | |
//把两个s1连接起来 | |
System.out.println(isSubString(s1 + s1, s2)); | |
} | |
public static boolean isSubString(String s1, String s2){ | |
int i; | |
i = s1.indexOf(s2); | |
return i >= 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment