text: #include <gtest/gtest.h>
  #include <iostream>
  #include <map>
  #include <vector>
  
  using namespace std;
  
  /**
   * This file is generated by leetcode_add.py
   *
   * 532.
   *      K-diff Pairs in an Array
   *
   * ––––––––––––––––––––––––––––– Description –––––––––––––––––––––––––––––
   *
   *   Given an array of integers ‘nums’ and an integer ‘k’ , return “the
   *   number of “unique” k-diff pairs in the array”
   *   A “k-diff” pair is an integer pair ‘(nums[i], nums[j])’ , where the
   *   following are
   *       -  ‘0 ≤ i < j < nums.length’
   *       -  ‘|nums[i] - nums[j]| = k’
   *    “Notice” that ‘|val|’ denotes the absolute value of ‘val’ .
   *
   * ––––––––––––––––––––––––––––– Constraints –––––––––––––––––––––––––––––
   *
   *   • ‘1 ≤ nums.length ≤ 10⁴’
   *   • ‘-10⁷ ≤ nums[i] ≤ 10⁷’
   *   • ‘0 ≤ k ≤ 10⁷’
   *
   */
  
  struct q532 : public ::testing::Test {
    // Leetcode answer here
    class Solution {
     public:
      int findPairs(vector<int> &nums, int k) {
        map<int, int> cnt;
        for (const auto &x : nums) ++cnt[x];
        int res = 0;
        for (auto &[num, remain] : cnt) {
          --remain;
          if (cnt.count(num + k) && cnt.at(num + k) > 0) {
            --cnt[num + k];
            remain = 0;
            ++res;
          }
        }
        return res;
      }
    };
  
    class Solution *solution;
  };
  
  TEST_F(q532, sample_input01) {
    solution = new Solution();
    vector<int> nums = {3, 1, 4, 1, 5};
    int k = 2;
    int exp = 2;
    int act = solution->findPairs(nums, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }
  
  TEST_F(q532, sample_input02) {
    solution = new Solution();
    vector<int> nums = {1, 2, 3, 4, 5};
    int k = 1;
    int exp = 4;
    int act = solution->findPairs(nums, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }
  
  TEST_F(q532, sample_input03) {
    solution = new Solution();
    vector<int> nums = {1, 3, 1, 5, 4};
    int k = 0;
    int exp = 1;
    int act = solution->findPairs(nums, k);
    EXPECT_EQ(act, exp);
    delete solution;
  }