C++ | Easy Understood Solution | map
We need to find pair whose differense is k.\nSo that we can store frequency to map and we will find, whether another key is exist or not whose difference is k.\
We need to find pair whose differense is k.\nSo that we can store frequency to map and we will find, whether another key is exist or not whose difference is k.\nif exist, then we will increment our ans by 1.\n\nLet\'s look at one example.\n**nums = [1,3,5,1,4], k = 2**\n\nNow store frequency to map:\n1-> 2\n3-> 1\n4-> 1\n5-> 1\n\nNow, iterate to map and find key difference of k. If found then increment ans+1.\n\nHere, keys two keys found **(1,3), (3,5)** whose difference is 2. So that **ans = 2**;\n\nWe need to also take care when k=0 given.\nSo that I have just decrement value by 1 and increment value by 1.\n\n```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        int ans = 0;\n        map<int,int> mp;\n        for(auto &x : nums){\n            mp[x]++;\n        }\n        for(auto &x : mp){\n            x.second--;\n            if(mp.find(x.first+k) != mp.end() and mp[x.first+k] >= 1)\n                ans++;\n            x.second++;\n        }\n        return ans;\n    }\n};\n```
[]