leetcode

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

2275.cpp (386B)


      1 class Solution {
      2   public:
      3     int largestCombination(const vector<int> &candidates) {
      4         int res = 0, maxi = *max_element(begin(candidates), end(candidates));
      5         for (int mask = 1, cnt = 0; mask <= maxi; mask <<= 1, cnt = 0) {
      6             for (int n : candidates)
      7                 cnt += (n & mask) > 0;
      8             res = max(res, cnt);
      9         }
     10         return res;
     11     }
     12 };