Skip to content

Commit 8d01381

Browse files
authored
Merge pull request #3757 from NotADucc/0203
create csharp/0203-remove-linked-list-elements.cs
2 parents d18732e + f138da7 commit 8d01381

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Solution
2+
{
3+
public ListNode RemoveElements(ListNode head, int val)
4+
{
5+
ListNode dummy = new ListNode(0, head);
6+
ListNode current = dummy;
7+
8+
while (current.next is not null)
9+
{
10+
if (current.next.val == val)
11+
{
12+
current.next = current.next.next;
13+
}
14+
else
15+
{
16+
current = current.next;
17+
}
18+
}
19+
return dummy.next;
20+
}
21+
}

0 commit comments

Comments
 (0)