class Solution {
public ListNode deleteNode(ListNode head, int val) {
ListNode dummy = new ListNode(-1, head);
ListNode pre = dummy;
while(pre.next != null && pre.next.val != val){
pre = pre.next;
}
pre.next = pre.next.next;
return dummy.next;
}
}
剑指 Offer 18. 删除链表的节点
最新推荐文章于 2024-08-14 11:57:07 发布