You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master/Algorithms , feel free to give a star :) )
std::vector<int> countingSort(std::vector<int> const & _nums) { using namespace std; vector<int> frequencies(100, 0); for(auto & num : _nums){ ++frequencies.at(num); } vector<int> sorted; sorted.reserve(1'000'000); size_t count = 0; for(auto & frqnc : frequencies){ while(frqnc--){ sorted.emplace_back(count); } ++count; } sorted.shrink_to_fit(); return sorted; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 2
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master/Algorithms , feel free to give a star :) )