Delete Node in a Linked List

 

237. Delete Node in a Linked List

Solution

  1. Copy the next node’s val to next.next node

  2. Move the pointer

def deleteNode(self, node):
    """
    :type node: ListNode
    :rtype: void Do not return anything, modify node in-place instead.
    """
    node.val = node.next.val
    node.next = node.next.next