Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'zlin'
- # class ListNode:
- # def __init__(self, x):
- # self.val = x
- # self.next = None
- class Solution:
- # @param head, a ListNode
- # @param k, an integer
- # @return a ListNode
- def rotateRight(self, head, k):
- if not (head and head.next):
- return head
- p1 = head
- list_size = 1
- while p1.next:
- p1 = p1.next
- list_size += 1
- run = list_size - k % list_size
- p1.next = head
- for i in range(run):
- p1 = p1.next
- head = p1.next
- p1.next = None
- return head
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement