lower_bound 与 upper_bound

单选题 难度 3

#binsearch#stl

两个函数差在哪?

题目

下面代码的输出是( )。

vector<int> v = {1,3,5,7,9};
cout << lower_bound(v.begin(), v.end(), 5) - v.begin() << " "
     << upper_bound(v.begin(), v.end(), 5) - v.begin() << endl;
  1. 2 3
  2. 2 2
  3. 3 3
  4. 1 2
来小码星球,动手写一遍 →