<s> class ListNode : <EOL> def __init__ ( self , x ) : <EOL> self . val = x <EOL> self . next = None <EOL> def __repr__ ( self ) : <EOL> if self : <EOL> return "<STR_LIT>" . format ( self . val , repr ( self . next ) ) <EOL> class Solution ( object ) : <EOL> def rotateRight ( self , head , k ) : <EOL> """<STR_LIT>""" <EOL> if not head or not head . next : <EOL> return head <EOL> n , cur = <NUM_LIT:1> , head <EOL> while cur . next : <EOL> cur = cur . next <EOL> n += <NUM_LIT:1> <EOL> cur . next = head <EOL> cur , tail = head , cur <EOL> for _ in xrange ( n - k % n ) : <EOL> tail = cur <EOL> cur = cur . next <EOL> tail . next = None <EOL> return cur <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> head = ListNode ( <NUM_LIT:1> ) <EOL> head . next = ListNode ( <NUM_LIT:2> ) <EOL> head . next . next = ListNode ( <NUM_LIT:3> ) <EOL> head . next . next . next = ListNode ( <NUM_LIT:4> ) <EOL> head . next . next . next . next = ListNode ( <NUM_LIT:5> ) <EOL> print Solution ( ) . rotateRight ( head , <NUM_LIT:2> ) </s>
