Skip to content

Latest commit

 

History

History

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

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

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