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 };