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
おすすめ
ランキング