Skip to content

Files

Latest commit

8dde2dd · Aug 1, 2024

History

History

delete-nodes-from-linked-list-present-in-array

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Aug 1, 2024
Jul 14, 2024
Jul 14, 2024
Jul 14, 2024

Delete nodes from linked list present in array

Problem link

Solutions

Solution.py

# https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/

class Solution:
    def modifiedList(
        self, nums: List[int], head: Optional[ListNode]
    ) -> Optional[ListNode]:
        nums = set(nums)

        def work(head):
            if not head:
                return head
            elif head.val in nums:
                return work(head.next)
            head.next = work(head.next)
            return head
        return work(head)

Tags