Speed up the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Speed up the code

What is the fastest way to compare elements in vector?Considering that vector contains 1k+ elements

4th Feb 2022, 3:07 PM
Sandra Kulibali
Sandra Kulibali - avatar
3 Answers
+ 1
You could do something like this: #include <algorithm> template <class T> static bool compareVectors(vector<T> a, vector<T> b) { std::sort(a.begin(), a.end()); std::sort(b.begin(), b.end()); return (a == b); }
7th Feb 2022, 7:24 AM
The_Fox
The_Fox - avatar
0
Thanks for the response. I think my question wasn't clear enough. I wanted to find the fastest way to compare elements in one vector with each other, if there are identical elements in the vector, return true
7th Feb 2022, 9:57 AM
Sandra Kulibali
Sandra Kulibali - avatar
0
Mmh. Ok. Don‘t the FASTEST way… :)
7th Feb 2022, 11:12 AM
The_Fox
The_Fox - avatar