Skip to content

Commit 50b5ec1

Browse files
done
1 parent cde20a8 commit 50b5ec1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
String Rotation:Assume you have a method isSubstring which checks if one word is a
3+
substring of another. Given two strings, sl and s2, write code to check if s2 is
4+
a rotation of sl using only one call to isSubstring (e.g.,"waterbottle" is a
5+
rotation of"erbottlewat").
6+
"""
7+
8+
def isSubstring(s1,s2):
9+
if s2 in s1: #check to see if the seqence of s2 is found in s1
10+
return True
11+
return False
12+
13+
def Rotation(s1,s2):
14+
"""
15+
if they are substring of each other then we first check its lenght
16+
"""
17+
if len(s1) != len(s2): #if there not the same lenght then there different woulds
18+
return False
19+
20+
else:
21+
s1+=s1 #waterbottlewaterbottle Anyroataion can be found here
22+
return isSubstring(s1,s2)
23+
24+
s1 = "waterbottle"
25+
s2 = "erbottlewat"
26+
27+
print(Rotation(s1,s2))

0 commit comments

Comments
 (0)