Rotate List
Problem statement
Rotate the singly linked list to the right by k positions and return the new head.
Function
rotateRight(head: ListNode, k: int) → ListNodeExamples
Example 1
head = [1,2,3,4,5]k = 2return = [4,5,1,2,3]The last two nodes move to the front.
Constraints
- The list contains at most
10^5nodes. 0 <= k <= 10^9.