How to check whether a vector is a subset of another in c++

后端 未结 4 1717

I am trying to find a simple way to check whether a vector is a subset of another without sorting the order of elements in the vector. Both the vectors contain random number

4条回答
  •  感动是毒
    2021-01-01 23:19

    With no sorting...

    template 
    bool isSubsetOrEqual(std::vector const& a, std::vector const& b) {
       for(auto const& av:a){
          if(std::find(b.begin(),b.end(),av)==b.end())
              return false;
       }
       return true;
    }
    

提交回复
热议问题