Calculate the length of the list and use k%length.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
if not head or k==0:
return head
l=head
count=0
while(not l==None):
l=l.next
count=count+1
r=k%count
if r==0:
return head
p=head
for i in range(count-r-1):
p=p.next
q=p.next
p.next=None
tmp=q
for i in range(r-1):
tmp=tmp.next
tmp.next=head
return q