Skip to content

Files

Latest commit

 

History

History
49 lines (36 loc) · 1.21 KB

_3217. Delete Nodes From Linked List Present in Array.md

File metadata and controls

49 lines (36 loc) · 1.21 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 06, 2024

Last updated : September 06, 2024


Related Topics : Array, Hash Table, Linked List

Acceptance Rate : 68.2 %


Solutions

Python

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def modifiedList(self, 
                     nums: List[int], 
                     head: Optional[ListNode]) -> Optional[ListNode]:
        dum = ListNode(next=head)
        dumCpy = dum
        nums = set(nums)

        while dum.next :
            if dum.next.val in nums :
                dum.next = dum.next.next
            else :
                dum = dum.next
        
        return dumCpy.next