haoel / leetcode

LeetCode Problems' Solutions
17.63k stars 4.92k forks source link

[Rotate List] there is a better solution #32

Closed ghost closed 9 years ago

ghost commented 9 years ago

https://github.com/haoel/leetcode/blob/ad62b9d82e8d72a3923881840b23532216c12982/src/rotateList/rotateList.cpp#L35-L36

Given the length n, you only need to loop about n~2n times if k is much more bigger than n.

haoel commented 9 years ago

You are right! let me do some improvement.

haoel commented 9 years ago

code change : https://github.com/haoel/leetcode/commit/356254b9189311f7bf6216bd002adf36c8988e26

(oops, seems github misses match the code commit message to close the issue.)

ghost commented 9 years ago

Great, more interesting than my two pointers version. :+1: