Files
Leetcode/83. Remove Duplicates from Sorted List/Solution.cs
Electrominch 01c5720116 Day10
2022-10-12 02:30:23 +03:00

26 lines
646 B
C#

namespace _83._Remove_Duplicates_from_Sorted_List;
public class Solution
{
public ListNode? DeleteDuplicates(ListNode? head)
{
ListNode? first = null;
ListNode? current = null;
while (head != null)
{
if (first == null)
first = current = head;
if (head.val == current!.val)
{
head = head.next;
continue;
}
current!.next = head;
current = current.next;
head = head.next;
}
if (current != null)
current.next = null;
return first;
}
}