所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。 class Solution: def reverseStr(self, s, k): """ :type s: str :type k: int :rtype: str """ # method one 字符串的切片和反序操作不能同时进行 res = '' for i in range(0,len(s),2*k): res = res + s[i:i+k][::-1] + s[i+k:i+2*k] return res 所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。