Re: [閒聊] 每日leetcode

作者: dont   2024-09-06 14:23:02
3217. Delete Nodes From Linked List Present in Array
## 思路
先把nums轉成set
掃linked list時, 如果下一個node的值在set裡面就跳過去
## Code
```python
class Solution:
def modifiedList(self, nums: List[int], head: Optional[ListNode]) ->
Optional[ListNode]:
nums = set(nums)
dummy = ListNode(-1, head)
curr = dummy
while curr.next:
if curr.next.val not in nums:
curr = curr.next
else:
curr.next = curr.next.next
return dummy.next
```
作者: sustainer123 (caster)   2024-09-06 14:26:00
大師
作者: oin1104 (是oin的說)   2024-09-06 14:27:00
大師
作者: DJYOMIYAHINA (通通打死)   2024-09-06 14:29:00
別捲了

Links booklink

Contact Us: admin [ a t ] ucptt.com