学习目标:
移除链表元素
学习内容:
给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。
class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
if head == None:
return head
head.next = self.removeElements(head.next, val)
if head.val == val:
return head.next
else:
return head