image_2021-11-17_15-59-40.png
35.3 KB
#N203. Remove Linked List Elements
problem link
#solution
problem link
#solution
class Solution {
public ListNode removeElements(ListNode head, int val) {
ListNode curr=head;
if(head==null) return head;
while(curr.next!=null){
if(curr.next.val==val)
curr.next=curr.next.next;
else
curr=curr.next;
}
if(head.val==val) return head.next;
return head;
}
}