Skip to content

Instantly share code, notes, and snippets.

@pratik7368patil
Created May 30, 2020 11:23
Show Gist options
  • Save pratik7368patil/59683f39dd97f16f0b5154a6de84f671 to your computer and use it in GitHub Desktop.
Save pratik7368patil/59683f39dd97f16f0b5154a6de84f671 to your computer and use it in GitHub Desktop.
Check Rotation in string
# this is a easy problem you know how rotation works.
# this problem can be sloved using index()
def check_rotation(string1, string2):
if len(string1) != len(string2): # check for base case
return "No"
con = string1*2 # concatenate string with itself
if con.count(string2) > 0: # check for string2 in concatenated string
return "Yes"
else:
return "No"
string1 = "awesomepython" # original string
string2 = "pythonawesome" # rorated string
print(check_rotation(string1, string2))
# the output will be "Yes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment