class Solution{
public ListNode removeElements(ListNode head, int val) {
ListNode node=new ListNode(-1);
node.next=head;
ListNode cur=node;
while(cur.next!=null){
if(cur.next.val==val){
cur.next=cur.next.next;
}else {
cur=cur.next;
}
}
return node.next;
}
}
java删除链表中等于给定值 val 的所有节点。
最新推荐文章于 2022-02-01 20:41:23 发布