Hello
Is it possible to find max element in STL set with complexity O(lgN) ?
Printable View
Hello
Is it possible to find max element in STL set with complexity O(lgN) ?
This should do the trick in constant time.Code:*set.rbegin();
Right, thank You... heh that was so easy :)
there it is, log(n) time as requested :)Code:max = *set.rbegin();
for (int i = 0; i < log(set.size()); i++) {
max = *set.rbegin();
}
return max;
Mhm thanks, but I think I will stick with O(1) :)