Remove Linked List Elements

Problem: Remove Linked List Elements

Just find the wanted node and remove it.

Code in Python:

class Solution(object):
    def removeElements(self, head, val):
        """
        :type head: ListNode
        :type val: int
        :rtype: ListNode
        """
        prev, node = ListNode(0), head
        prev.next, ans = head, prev
        while node:
            if node.val == val:
                prev.next, node = node.next, node.next
            else:
                prev, node = node, node.next
        return ans.next

results matching ""

    No results matching ""