Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 612 Bytes

203._remove_linked_list_elements.md

File metadata and controls

38 lines (24 loc) · 612 Bytes

###203. Remove Linked List Elements

题目: https://leetcode.com/problems/remove-linked-list-elements/

难度:

Easy

AC代码如下:

class Solution(object):
    def removeElements(self, head, val):
        """
        :type head: ListNode
        :type val: int
        :rtype: ListNode
        """
        dummy = ListNode(-1)
        dummy.next = head
    
        cur = dummy
    
        while cur.next:
            if cur.next.val == val:
                cur.next = cur.next.next
            else:
                cur = cur.next
    
        return dummy.next