Created
May 30, 2020 11:23
-
-
Save pratik7368patil/59683f39dd97f16f0b5154a6de84f671 to your computer and use it in GitHub Desktop.
Check Rotation in string
This file contains hidden or 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
# 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