Python iterative O(n) one line


  • 0
    A
    class Solution(object):
        def reverseStr(self, s, k):
            """
            :type s: str
            :type k: int
            :rtype: str
            """
            return ''.join([s[i:i+k][len(s[i:i+k])::-1]+s[i+k:i+2*k] for i in range(0, len(s), 2*k)])
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.