leetcode

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

1558.cpp (366B)


      1 class Solution {
      2     static constexpr const int size = sizeof(int) * 8 - 1;
      3 
      4   public:
      5     int minOperations(const vector<int> &nums) {
      6         int mini = INT_MAX, res = 0;
      7         for (const int n : nums) {
      8             if (n) mini = min(mini, __builtin_clz(n));
      9             res += __builtin_popcount(n);
     10         }
     11         return max(0, res + size - mini);
     12     }
     13 };