[bug]
[failure case] 1 2 3 3 2 1
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode removeDuplicateNodes(ListNode head) {
Set<Integer> set = new HashSet<>();
ListNode p = new ListNode(-1);
ListNode c = head;
p.next = c;
while(c!=null){
if(!set.contains(c)){
set.add(c.val);
if(p.next!=c){
p.next = c;
}
p = p.next;
c = c.next;
}
else {
c = c.next;
}
}
p.next = null;
return head;
}
}```