题解 | #删除链表的节点#
删除链表的节点
https://www.nowcoder.com/practice/f9f78ca89ad643c99701a7142bd59f5d
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { public ListNode deleteNode (ListNode head, int val) { while(head.val == val){ head = head.next; } ListNode pre = head; while(pre != null && pre.next!=null){ if(pre.next.val == val){ pre.next = pre.next.next; }else{ pre = pre.next; } } return head; } }