Given a list, rotate the list to the right by k places, where k is non-negative.
For example:
Given 1->2->3->4->5->nullptr and k = 2, return 4->5->1->2->3->nullptr.
首先确定题目要求的旋转都需要哪些结点:dummy头结点、结点K、尾结点,然后再去定位。注意,题目中提到前置条件k是非负数,所以要判断k是否越界。最终旋转时注意不要形成循环链表,导致打印链表时死循环!
Leetcode解题-链表(2.2.6)RotateList
原文地址:http://blog.csdn.net/dc_726/article/details/44699867