Simple Python Solution

  • 0
    class Solution:
        # @param {ListNode} node
        # @return {void} Do not return anything, modify node in-place instead.
        def deleteNode(self, node):
            if node is None: return
            next_node =
            next_next =
            node.val = next_node.val
   = next_next

  • 0

    if you delete the last node? then will give a error about 'no next'

  • 1

    You can do it in an easier way:

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

  • 0

    How about is None? Why we don't need to take this into consideration?

Log in to reply

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