leetcode

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

2859.cpp (272B)


      1 class Solution {
      2   public:
      3     int sumIndicesWithKSetBits(vector<int> &nums, int k) {
      4         int res = 0;
      5 
      6         for (unsigned i = 0; i < size(nums); i++) {
      7             if (popcount(i) != k) continue;
      8             res += nums[i];
      9         }
     10 
     11         return res;
     12     }
     13 };