How to retrieve elements from sorted TreeSet using Binary Search?

前端 未结 3 865
春和景丽
春和景丽 2021-01-14 10:20

I am trying to merge multiple sorted lists into one TreeSet.. And then I am thinking to apply Binary Search algorithm on that TreeSet to retrieve the element in O(log n) tim

3条回答
  •  感动是毒
    2021-01-14 11:11

    You could use TreeSet.floor(), which according to the docs

    Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.

提交回复
热议问题