def rotate_right(head, k):
if not head or not head.next:<EOL><INDENT>return head<EOL><DEDENT>current = head<EOL>length = <NUM_LIT:1><EOL>while current.next:<EOL><INDENT>current = current.next<EOL>length += <NUM_LIT:1><EOL><DEDENT>current.next = head<EOL>k = k % length<EOL>for i in range(length-k):<EOL><INDENT>current = current.next<EOL><DEDENT>head = current.next<EOL>current.next = None<EOL>return head<EOL>
:type head: ListNode
:type k: int
:rtype: ListNode