leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1356.cpp (316B)


      1 class Solution {
      2   public:
      3     vector<int> sortByBits(vector<int> &arr) const {
      4         sort(begin(arr), end(arr), [](int a, int b) {
      5             const int x = __builtin_popcount(a);
      6             const int y = __builtin_popcount(b);
      7             return x != y ? x < y : a < b;
      8         });
      9         return arr;
     10     }
     11 };