class Solution:
def reverseStr(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
new_list = list(s)
i = 0
while i< len(s):
if i+k > len(s):
new_list[i:] = new_list[i:][::-1]
else:
new_list[i:i+k] = new_list[i:i+k][::-1]
i = i+k*2
return ''.join(new_list)
No comments:
Post a Comment