1
class Solution {
2
public ListNode deleteDuplicates(ListNode head) {
3
if (head == null) return head;
4
ListNode temp = head;
5
int last = -1;
6
int[] array = new int[201];
7

8
// zero == index 100
9
// one == index 101;
10
// -100 == index 0;
11

12
while (temp != null) {
13
array[temp.val + 100]++;
14
temp = temp.next;
15
}
16

17
for (int i = 0; i < 201; i++) {
18
if (array[i] == 1) {
19
last = i;
20
}
21
}
22

23
if (last == -1) return null;
24
temp = head;
25

26
for (int i = 0; i < 201; i++) {
27
if (array[i] == 1) {
28
temp.val = i - 100;
29
if (i == last) {
30
temp.next = null;
31
break;
32
}
33
temp = temp.next;
34
}
35
}
36
temp.next = null;
37

38
return head;
39
}
40
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0