Binary Search solution [Java]
\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        Arrays.sort(nums);\n        int count=0;\n        for(int i=0;i<nums.length;i++)\n   
```\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        Arrays.sort(nums);\n        int count=0;\n        for(int i=0;i<nums.length;i++)\n        {  \n            int low=i+1;\n            int high=nums.length-1;\n            while(low<=high)\n            {\n                int mid=low+(high-low)/2;\n                if(nums[mid]-nums[i]==k)\n                {count++;\n                 break;\n                }else if(nums[mid]-nums[i]>k)\n                    high=mid-1;\n                else\n                    low=mid+1;\n            }\n            while(i!=nums.length-1 && nums[i+1]==nums[i])\n                i++;\n        }\n        return count;\n    }\n}\n```
['Binary Tree', 'Java']