Skip to content

Commit 6f71db7

Browse files
committed
completed 1.9
1 parent e93b734 commit 6f71db7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
""" 1.9 String Rotation: 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. """
22

3+
34
def is_rotation(s1, s2):
45
""" Example inputs
56
67
>>> is_rotation("waterbottle", "erbottlewat")
7-
True
8+
True
9+
"""
10+
if len(s1) != len(s2) or len(s1) == 0:
11+
return False
12+
13+
superstring = s1 + s1
14+
return isSubstring(superstring, s2)
15+
16+
17+
# theoretically this should work, hard to test though
18+
19+
20+
21+
22+
23+
24+

0 commit comments

Comments
 (0)