Leetcode 61: Rotate List

This is an O(n) time, O(1) space solution. Find out list length by iterating through it. Recalculate k by mod len to reduce k to less than len. If new k is 0 return. Use slow and fast pointers to navigate fast to one before last and slow to one before new head. Rewire the pointers in these positions. So, split list after slow and join fast (last) to head. Return new head (node after slow).

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.