This commit is contained in:
Electrominch
2022-10-08 01:07:50 +03:00
parent 5cae083979
commit c019e8856c
13 changed files with 271 additions and 7 deletions

View File

@@ -0,0 +1,29 @@
namespace _203._Remove_Linked_List_Elements;
public class Solution
{
public ListNode? RemoveElements(ListNode? head, int val)
{
ListNode? first = null;
ListNode? current = null;
while (head != null)
{
if (head.val == val)
{
head = head.next;
continue;
}
if (first == null)
first = current = head;
else
{
current!.next = head;
current = current.next;
}
var buf = head;
head = head.next;
buf.next = null;
}
return first;
}
}