Day8-9
This commit is contained in:
26
83. Remove Duplicates from Sorted List/Solution.cs
Normal file
26
83. Remove Duplicates from Sorted List/Solution.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user