efficient way to get key from std::map value

后端 未结 4 2047
旧时难觅i
旧时难觅i 2021-01-18 00:46

I have a map as below :

std::map< std::string ,int> mapobj;
mapobj[\"one\"] = 1;
mapobj[\"two\"] = 2;
mapobj[\"three\"] =3 ;

how to g

4条回答
  •  孤独总比滥情好
    2021-01-18 01:03

    how to get key when input is value

    1. First, there is no guarantee that value is unique. I realize that you are saying it is unique. Still, conceptually speaking, this is something to keep in mind when looking at the problem.

    2. Second, std::map is not sorted by value. Hence, the most efficient algorithm to look for a value will be O(N) on an average.

提交回复
热议问题