Skip to Main Content

Remove Linked List Elements

Problem URL:Remove Linked List Elements

My Solution:

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

def removeElements(head: Optional[ListNode], val: int) -> Optional[ListNode]:
    new_node = ListNode(0, head)
    curr = new_node
    while curr:
        if and == val:
            curr =


Let's Connect

Twitter GitHub LinkedIn