unordered set intersection in C++

后端 未结 4 1284
梦如初夏
梦如初夏 2021-01-05 03:49

Here is my code, wondering any ideas to make it faster? My implementation is brute force, which is for any elements in a, try to find if it also in b, if so, put in result s

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 04:39

    You can do it with std::copy_if()

    std::copy_if(a.begin(), a.end(), std::inserter(c, c.begin()), [b](const int element){return b.count(element) > 0;} );
    

提交回复
热议问题