Hi everyone,
I have an array like : a = [3,3,4,3]
so a[2] = 4 is an exception, I want to get another b, which b = 3 (popular value of a). Which is the best method to do that in the case a has many value inside.
Thank you !
Hi everyone,
I have an array like : a = [3,3,4,3]
so a[2] = 4 is an exception, I want to get another b, which b = 3 (popular value of a). Which is the best method to do that in the case a has many value inside.
Thank you !
One way could be to use a std::map or std::unordered_map to map numbers to their current counts in the array. You then pick the number with the highest count.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)