Friday, September 20, 2013
[LeetCode] Anagrams 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.
Idea:
link the tail to head to construct a circle
start from head until stop by total - (k%total)
set tail.next to null to break the circle
No comments :
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments ( Atom )
No comments :
Post a Comment