题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0cfb149998c281c99358eaea71b7e1f6.png)
代码
class Solution {
public ListNode deleteNode(ListNode head, int val) {
if(head.val == val) return head.next;
ListNode pre = head, cur = head.next;
while(cur != null && cur.val != val) {
pre = cur;
cur = cur.next;
}
if(cur != null) pre.next = cur.next;
return head;
}
}
结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3b4e3871a6dabf0876ccea63210a97eb.png)