Clean python code


  • 1
    class Solution(object):
        def rotateRight(self, head, k):
            n, pre, current = 0, None, head
            while current:
                pre, current = current, current.next
                n += 1
    
            if not n or not k % n:
                return head
    
            tail = head
            for _ in xrange(n - k % n - 1):
                tail = tail.next
    
            next, tail.next, pre.next = tail.next, None, head
            return next

Log in to reply
 

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