题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f1e0dd2337f2f6a3fbcb510a8c4dd67c.png)
解法
class Solution:
def deleteNode(self, head: ListNode, val: int) -> ListNode:
node = head
if head.val == val: #如果head就相等的话,那么直接返回head.next
return head.next
while head.next: #如果head不相等,那么遍历链表找到相等的节点
if head.next.val == val:
head.next = head.next.next
return node
head = head.next
return node