541. Reverse String II
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 52% Topics: Two Pointers, String
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def reverseStr(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
s = list(s)
for i in xrange(0, len(s), 2*k):
s[i:i+k] = reversed(s[i:i+k])
return "".join(s)
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions