53. Rotate List

Given a singly linked list head and an integer k. Rotate the list to the right by k places and return the new head.
Example 1
Input: head = [1,2,3,4,5], k = 2
Output: [4,5,1,2,3]
Explanation: The last two nodes are moved to the front.
Example 2
Input: head = [0,1,2], k = 4
Output: [2,0,1]
Explanation: The rotation is equivalent to `k % length = 1`.
linked listmedium
JavaScript
Loading...
Line 1, Char 1