Rotate List

Question (LC.61)

Given a list, rotate the list to the right by k places, where k is non-negative.

Example

Input: 1->2->3->4->5->null, 2
Output: 4->5->1->2->3->null

Input: 1->2->3->4->5->null, 6
Output: 5->1->2->3->4->null !!!

Analysis

How do we get to the ith node in singly linked list? Get the total length. Then for loop until (len - k % len).

Code

later

Last updated