💚[C++] 95% Fast and Easy Solution Explained | HASHMAP
Welcome to abivilion\'s solution. Kindly Upvote for supporting this article.\n\nSOLUTION\nTC - O(n)\nSC - O(N)\n\n\nclass Solution {\npublic:\n    int findPairs
**Welcome to abivilion\'s solution. Kindly Upvote for supporting this article.**\n\n**SOLUTION**\n**TC - O(n)**\n**SC - O(N)**\n\n```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        \n        unordered_map<int,int>st;\n        int count=0;\n        \n\t\t//storing in map\n        for(auto &it:nums)\n            st[it]++;\n\n       // if k is 0, then which element FREQUENCY >1 can give 0\n        if(k==0) \n        {\n            for(auto &ko:st) if(ko.second>1) count++;\n                \n        }\n\n   // if k is any other number then ,difference can currentnum+k is present then the pair can give k as a resultant\n   // a-b = c\n   // a= c+b\n   // b =c-a\n        else\n        for(auto &ki:st)\n        {\n            if(st.count(ki.first+k)) count++;\n        }\n        \n        return count;\n    }\n};\n```
['C', 'C++']