leetcode

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

2860.cpp (398B)


      1 class Solution {
      2   public:
      3     int countWays(vector<int> &nums) const {
      4         sort(begin(nums), end(nums));
      5 
      6         const int n = size(nums);
      7         int res = 0, sel = 0;
      8         for (int i = 0; i < n - 1; i++) {
      9             if (i + 1 <= nums[i]) continue;
     10             if (i + 1 < nums[i + 1]) res++;
     11         }
     12 
     13         if (n > nums[n - 1]) res++;
     14         return res + (nums[0] != 0);
     15     }
     16 };