C++ Two solutions
\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n    //      time O(nlgn) space O(1)\n    //     sort(nums.begin(),nums.end());\n    
```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n    //      time O(nlgn) space O(1)\n    //     sort(nums.begin(),nums.end());\n    //     int n=nums.size();\n    //     int count=0;\n    //     for(int i=0;i<n;i++){\n    //         if(i!=0&&nums[i]==nums[i-1])continue;\n    //         bool res=binary_search(nums.begin()+i+1,nums.end(),nums[i]+k);\n    //         if(res){\n    //             count++;\n    //         }     \n    //     }\n    //     return count;\n    // }\n        \n        //      time O(n) space O(n)\n        int n=nums.size();\n        int count=0;\n        unordered_map<int,int> lookup;\n        if(k==0){\n            for(int i=0;i<n;i++){\n                if(lookup[nums[i]]==1){\n                    count++;\n                }    \n                lookup[nums[i]] =lookup[nums[i]]+1;\n            }\n        }else{\n            for(int i=0;i<n;i++){\n                if(!lookup.count(nums[i])){\n                    if(lookup.count(nums[i]-k)){\n                        count++;\n                    }\n                    if(lookup.count(nums[i]+k)){\n                        count++;\n                    }\n                    lookup[nums[i]]+=1;\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['Binary Tree']