How do I use a TreeSet in Java that allows Duplicates?
问题 I want a data structure with priority queue functions in O(logn) time and also be able to delete a specific element that's not necessarily the head in O(logn) time. I heard the TreeSet in java does it but does not allow Duplicates, How do i get around this? 回答1: Use TreeMap which allows insertion in log n time and deletion in log n time. You can have there TreeMap<Integer,Integer> where key stores the value of element and value stores the frequency of the element. If you need to do only