-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution82.cs
38 lines (32 loc) · 958 Bytes
/
Solution82.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution82
{
/// <summary>
/// 82. Remove Duplicates from Sorted List II - Medium
/// <a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii">See the problem</a>
/// </summary>
public ListNode DeleteDuplicates(ListNode head)
{
var dummy = new ListNode(0, head);
var prev = dummy;
var current = head;
while (current != null)
{
if (current.next != null && current.val == current.next.val)
{
while (current.next != null && current.val == current.next.val)
{
current = current.next;
}
prev.next = current.next;
}
else
{
prev = prev.next;
}
current = current.next;
}
return dummy.next;
}
}