237. Delete a Node in a Linked List
Last Updated: 2020.06.02
Question Source: Leetcode
Since we don’t have the pointer to the previous node, we can only get rid of the next node.
This effectively results in the singly-linked list looking like it has “deleted” the given node.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
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