Determing if one string is a rotation of another
I have an assignment for my computer science 1 class I could really use some help on. Here's exactly what it says:
Assume you have a method isSubstring which checks if one word is a substring of another, ex: isSubstring("water", "ter") returns true.
Given two strings s1 and s2, write code to check if s2 is a rotation of s1 using isSubstring, ex: "waterbottle" is a rotation of "erbottlewat"
I figured a way to put all the characters into an array and then just shuffle the order one letter at a time and compare that to the original. Problem is that the code has to use the isSubstring method mentioned. Any ideas?
Re: Determing if one string is a rotation of another
You need to find where a substring of the first String is a substring of the second String. For example:
Is waterbottle a substring of erbottlewat? No.
Is aterbottle a substring of erbottlewat? No.
Is terbottle a substring of erbottlewat? No.
Is erbottle a substring of erbottlewat? Yes.
Now you have a location you can chop the first String in two at that location, concatenate them back together in the opposite order and compare to the second String.