64ms python solution?1


  • 0
    2

    It says it runs only 64 ms, in Python?! I don't buy that. But whatever.

    class Solution(object):
    def reverseKGroup(self, head, k):
        """
        :type head: ListNode
        :type k: int
        :rtype: ListNode
        """
        if not head or not head.next:
            return head
    
        tail = head
        for i in range(k):
            if not tail:
                return head
    
            tail = tail.next
    
        tail = self.reverseKGroup(tail, k)
    
        for i in range(k):
            next = head.next
            head.next = tail
            tail = head
            head = next
    
        return tail

  • 0
    Z

    bravo!
    although I won't spent time figuring it out this ...


Log in to reply
 

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