I need to check if a std::set
contains element/elements in a range. For example, if the set is a set<int>
{1, 2, 4, 7, 8}
, and given an int
interval [3, 5]
(inclusive with both endpoints), I need to know if it has elements in the set. In this case, return true. But if the interval is [5, 6]
, return false. The interval may be [4, 4]
, but not [5, 3]
.
Looks like I can use set::lower_bound
, but I am not sure whether this is the correct approach. I also want to keep the complexity as low as possible. I believe using lower_bound
is logarithmic, correct?