Detecting rotated string

Q. 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 (e.g “waterbottle” is a rotation of “erbottlewat”)

def is_rotation(s1,s2):
    if s1 == "" and s2 == "":
        return True
    elif len(s1) != len(s2):
        return False
        if s2 in s1+s2:
            return True
            return False
if __name__ == "__main__":
    print is_rotation("waterbottle","erbottlewat")
    print is_rotation("Jyoti Sharma", "Sharma")


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s