[LC] 203. Remove Linked List Elements
Posted xuanlu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LC] 203. Remove Linked List Elements相关的知识,希望对你有一定的参考价值。
Remove all elements from a linked list of integers that have value val.
Example:
Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeElements(self, head: ListNode, val: int) -> ListNode: dummy = ListNode(-1) dummy.next = head cur = dummy while cur.next is not None: if cur.next.val != val: cur = cur.next else: cur.next = cur.next.next return dummy.next
以上是关于[LC] 203. Remove Linked List Elements的主要内容,如果未能解决你的问题,请参考以下文章
[LC]203题 Remove Linked List Elements (移除链表元素)(链表)
203. Remove Linked List Elements
203. Remove Linked List Elementseasy