forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_2095.java
27 lines (24 loc) · 765 Bytes
/
_2095.java
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
package com.fishercoder.solutions;
import com.fishercoder.common.classes.ListNode;
import java.util.ArrayList;
import java.util.List;
public class _2095 {
public static class Solution1 {
public ListNode deleteMiddle(ListNode head) {
List<Integer> list = new ArrayList<>();
while (head != null) {
list.add(head.val);
head = head.next;
}
ListNode pre = new ListNode(-1);
ListNode tmp = pre;
for (int i = 0; i < list.size(); i++) {
if (i != list.size() / 2) {
tmp.next = new ListNode(list.get(i));
tmp = tmp.next;
}
}
return pre.next;
}
}
}