s1= "waterbottle"
s2 = "erbottlewat"
s1s1= "waterbottlewaterbottle"
s2 = "erbottlewat"
2. Implementation
public static boolean isRotation(String s1, String s2) { int len = s1.length(); // check that s1 and s2 are equal length and not empty if ( len == s2.length() && len > 0 ) { /* concatenate s1 and s1 within new buffer */ String s1s1 = s1 + s1; return isSubstring(s1s1,s2); } return false; }3. Similar Ones
No comments:
Post a Comment