A corner case to consider


  • 0
    N

    There is a trick: if k is > than the list's length, you can still rotate the list. You have to consider that case.

    Also, you don't need to count number of nodes in the list. Just use 2 pointers, the first one advanced k times ahead, than move both forward until the first hit the end, then truncate at the 2nd trailing pointer, use that as the new head.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.