public ListNode deleteDuplicates(ListNode head) {
        ArrayList<Integer> visited = new ArrayList<Integer>();
        
        if(head == null) return null;
        
        ListNode p = head;
        visited.add(new Integer(head.val));
        
        while(p != null && p.next != null) {
            if(visited.contains(new Integer(p.next.val))){
                //remove p.next
                p.next = p.next.next;
            }else {
                visited.add(new Integer(p.next.val));
                p = p.next;
            }
        }
        return head;
    }