leetcode

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

2537.cpp (402B)


0 class Solution { 1 public: 2 long long countGood(const vector<int> &nums, int k) const { 3 unordered_map<int, int> count; 4 const int n = size(nums); 5 long long res = 0; 6 7 for (int i = 0, j = 0; j < n; j++) { 8 k -= count[nums[j]]++; 9 while (k <= 0) 10 k += --count[nums[i++]]; 11 res += i; 12 } 13 14 return res; 15 } 16 };