Skip to content

Commit 6883d36

Browse files
authored
Create perform-string-shifts.py
1 parent c9ec3f9 commit 6883d36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/perform-string-shifts.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n + l)
2+
# Space: O(l)
3+
4+
class Solution(object):
5+
def stringShift(self, s, shift):
6+
"""
7+
:type s: str
8+
:type shift: List[List[int]]
9+
:rtype: str
10+
"""
11+
left_shifts = 0
12+
for direction, amount in shift:
13+
if not direction:
14+
left_shifts += amount
15+
else:
16+
left_shifts -= amount
17+
left_shifts %= len(s)
18+
return s[left_shifts:] + s[:left_shifts]

0 commit comments

Comments
 (0)