Simple Python Solution


  • 0
    S
    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 = node.next
            next_next = next_node.next
            
            node.val = next_node.val
            node.next = next_next

  • 0
    J

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


  • 1
    C

    You can do it in an easier way:

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

  • 0
    J

    How about node.next 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.