C++ How to find the biggest key in a std::map?

后端 未结 4 1005
走了就别回头了
走了就别回头了 2020-12-14 00:00

At the moment my solution is to iterate through the map to solve this.

I see there is a upper_bound method which can make this loop faster, but is there

4条回答
  •  余生分开走
    2020-12-14 00:43

    The entries in a std::map are sorted, so for a std::map m (assuming m.empty() is false), you can get the biggest key easily: (--m.end())->first

提交回复
热议问题