reverse_string_ii

  • 2022-12-14
  • 浏览 (611)

reverse_string_ii.py 源码

# 反转字符串II

class Solution:
    def reverseStr(self, s: str, k: int) -> str:
        s = list(s)
        for i in range(0, len(s), 2 * k):
            s[i:i+k] = reversed(s[i:i+k])
        return ''.join(s)

你可能感兴趣的文章

first_unique_char

implement_strstr

is_palindrome

0  赞