python concise recursive


  • 0
    Z
    class Solution(object):
        def reverseKGroup(self, head, k):
            if head:
                node = head
                for _ in range(k - 1):
                    node = node.next
                    if not node:
                        return head
                prev = self.reverseKGroup(node.next, k)
                while prev is not node:
                    prev, head.next, head = head, prev, head.next
                return prev

Log in to reply
 

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