-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_2095.cs
32 lines (30 loc) · 856 Bytes
/
No_2095.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
namespace LeetCode
{
public class No_2095
{
public ListNode? DeleteMiddle(ListNode head)
{
if (head.next == null)
return null;
if (head.next.next == null)
{
head.next = null;
return head;
}
else
{
ListNode s = new ListNode(-1, head.next), f = new ListNode(-1, head.next), p = new ListNode(-1, head);
while (f.next != null && f.next.next != null)
{
s.next = s.next.next;
p.next = p.next.next;
f.next = f.next.next.next;
}
p.next.next = s.next.next;
s.next.next = null;
GC.Collect();
}
return head;
}
}
}