Skip to Main Content

Delete Node in a Linked List

Problem URL:Delete Node in a Linked List

My Solution

Python

Modified In-Place.

# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


def deleteNode(node):
    while node.next is not None:
        node.val = node.next.val

        if node.next.next is None:
            node.next = None
        else:
            node = node.next

Let's Connect

Twitter GitHub LinkedIn