public static ListNode deleteDuplicates(ListNode head) {//exceeded time limit
        if (head == null || head.next == null) {
            return head;
        }
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode prev = dummy;
        ListNode p = head;

        java.util.HashMap<Integer, Integer> map1 = new java.util.HashMap<Integer, Integer>();

        while (p != null) {
            if (map1.containsKey(p.val)) {
                if (p.next != null) {
                    prev.next = p.next;
                    p = prev.next;
                }
                else {
                    prev.next = p.next;
                }
            }
            else {
                map1.put(p.val, 0);
                if (p.next != null) {
                    prev = prev.next;
                    p = prev.next;
                }
                else {
                    break;
                }
            }
        }
        ListNode t = dummy.next;
        while (t != null) {
            System.out.println(t.val);
            t = t.next;
        }
        return null;
    }