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 的所有节点。
猜你喜欢
转载自blog.csdn.net/Nabandon/article/details/104069146
今日推荐
周排行