Why LeetCode accepted such stupid question?


  • 103
    S

    This question is stupid and should be deleted intermediately.


  • 68
    B

    I was kind of doubting the correctness of the problem since I thought without giving a head, I cannot delete the node. Then I found that some guys are smart. They change value. :D!


  • 1

    +1. At first I thought this is an impossible mission. Until I saw your "change value". :D!


  • 9

    Why/how is it stupid?


  • 1
    Y

    +1 I was doubting why return void instead of head......


  • 0
    R

    upvote for stupidity


  • 23

    I find it more stupid to call this stupid without saying why it's supposedly stupid or to upvote here without saying why it's supposedly stupid. 16 people so far and nobody is capable of providing any reasoning? Then it can't really be that stupid.


  • 7
    S

    Because this question encourages us to use awkward method or dummy "skills" to solve it, which deviates the general principles for linked list manipulations. When we are asked to solve questions related to linked list, it is widely accepted to just use just node operations and it is not allowed to change node's value. If the values of nodes are allowed to be changed, will it make sense to call this problem related to linked list? If values are allowed to be changed, why don't we solve it in the form of arrays?


  • 0
    A

    what is changing value?


  • 3

    Thanks for the explanation. I btw dislike the problem a bit as well, though just because of the wording, asking us to delete the node. Otherwise I think it's an alright problem. Yes, it requires to break a usual convention, but that's not necessarily bad. Let's think outside of the box for once.

    This might even be used in the real world. Better not in a public API, at least not without warning, as the caller might have a reference to the following node, so deleting that is improper. But it could be used internally. Imagine some LRU cache implementation with a maximum capacity, for example, with a linked list holding the values in LRU order. When a value is used, it needs to be removed from its current list place. Which I think could be done like in this problem here. And since it's an internal implementation detail, it would also be safe.


  • 2

    "why don't we solve it in the form of arrays?"

    I don't understand why you say this. Makes no sense. Removing a value from an array takes O(n) time. Removing it from a linked list takes O(1) time. The latter is far better. That's why.


  • 0
    S

    The operations of linked list should base on pointer operations, however, this question misguide most people.
    Solving such kind of question is nothing.
    I say "why don't we solve it in the form of arrays?", because when values can be changed, how could you say linked lists are different from arrays? The values of array entries are changed very often, indeed!


  • 0

    I say "why don't we solve it in the form of arrays?", because when values can be changed, how could you say linked lists are different from arrays?

    I already told you. They vastly differ in the speed of operations. For some things arrays are better, for some things linked lists are better. How is that not obvious? That's the whole point for having different data structures in the first place. People don't use linked lists because they find it oh so cool to handle pointers, they use them for their advantages.


  • 3
    C

    like this:

    def deleteNode(self, node):
        node.val = node.next.val
        node.next = node.next.next

  • 0
    Z

    Aha, finally I get the point. Thank you for inspiring me.


  • 0
    J

    it's leaking memory, you can see this:
    https://leetcode.com/discuss/45977/2-lines-with-o-1-time-c


  • 0

    @John1993 No it's not. That's Python, which handles it for you.


  • 0
    J

    i did't see it, thank you!


  • 0
    S

    I think it's an interesting question ^-^


  • 1
    L

    very smart! But I don't think the solution is usable in reality, because if some ListNode has been referred before, its value will be changed. (excuse my bad English


Log in to reply
 

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