I am not sure if the example in the question is correct.


  • 0
    K

    Hello all,
    In the example,
    Given 1->2->3->4->5->NULL and k = 2,
    return 4->5->1->2->3->NULL.

    When k == 2, why is the list 4->5->1->2->3->NULL but not 3->4->5->1->2->NULL?

    If the example is correct, then in test case, 1->2->NULL, k = 1, why is the answer 2->1->NULL?

    Thanks all in advance.


  • 0

    We need to move elements to right, so we remove that many elements from end and add them to head.

    k can be greater than lenght.
    The trick here is to move to k%length . then you get the new head,


Log in to reply
 

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