Why the expected result is that?


  • 0
    U

    Input: {1,2}, 3
    Output: {1,2}
    Expected: {2,1}

    it is meanless, or the result should be {1,2}, since
    input {1,2} 2
    output is {1,2}


  • 1
    S

    'Rotate by 1' means to move the last element to the very beginning.
    'Rotate by n' means to repeat 'Rotate by 1' n times.
    So for {1,2}, 3, what you do is basically swap the nodes 3 times, and in the end, you get {2, 1}.
    {1, 2}, 2 is naturally 2 because it is what you should get after 2 swaps.


  • 2

    from what I understand, "rotate by n' means the nth node from the end of the list will become the new head. Then, you attach the original node 0 till n-1 to it (node n till last node);


  • 0
    X

    me too,me too ,


Log in to reply
 

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