Is there any one think this is a stupid one? Wtf difference with 2 pointers 1 pass with 1 pointer 2 pass?


  • 6
    P

    It is meaningless to use the 2 pointers technique, you won't get benefit from that, it still has the same dereference compare to 1 pointer 2 pass.

    You want to have cache benefit when n is small?

    I hope leetcode can remove this misleading question because it encourages those people to use this "technique" to "optimize" code. It is silly.


  • 7
    G

    I Agree. This problem is meaningless.

    There are at least three solution:

    • get the length of list in the first pass, remove the element in the second pass
    • use two pointers. keep the distance equal to n (stupid, no performance benefit, hard to program)
    • use recursion. remove the element when exiting from the recursion (very stupid, linear space usage)

  • 0
    K

    I disagree. In real world problems, if N was equal to 10 billion, it would suck to have to go through that list twice.


Log in to reply
 

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