python recursion way


  • 0
    J

    '''
    class Solution:
    def reverseString(self, s):
    """
    :type s: str
    :rtype: str
    """
    # if s is "":
    # return ""
    # else:
    # return self.reverseString(s[1: ])+s[0]
    l = len(s)
    if l < 2:
    return s
    return self.reverseString(s[l//2:]) + self.reverseString(s[:l//2])
    '''


Log in to reply
 

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