61 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.
Example:
The Idea: Find the length of the list, and store the tail end of the list. Then mod k with the length of the list, because when k>length list, the rotation would cycle about itself, leaving a remainder behind. Then subtract k with the length. This will be the pivot point we want to get to from head. Point the tail end to the front of the list and have the pivot point to null.
Complexity: O(n) time and O(1) space
Last updated