Tuesday, August 5, 2014

Rotate List

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->NULL and k = 2,
return 4->5->1->2->3->NULL.
实现题型!

方法就是双指针. 一个解惑点: 如果当k的值大于了整个List的长度的时候, 那就是说明rotate了一圈之后在继续. 所以无论k是多少, 要rotate的个数永远是k % n. 

No comments:

Post a Comment