leetcode203-Remove Linked List Elements移除链表元素

leetcode203-Remove Linked List Elements移除链表元素

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def removeElements(self, head, val):
        """
        :type head: ListNode
        :type val: int
        :rtype: ListNode
        """
        if head == None:
            return None
        current=head
        while current.next != None:
            if current.next.val==val:
                current.next=current.next.next
                continue
            current=current.next
        if head.val==val:
            return head.next
        else:
            return head