[Java/Binary Search] Easy to understand
Try search for each element because we need to find only unique element so discard those element that have been traversed,\n\nclass Solution \n{\n    public int
Try search for each element because we need to find only unique element so discard those element that have been traversed,\n```\nclass Solution \n{\n    public int findPairs(int[] nums, int k) \n    {\n        int n = nums.length;\n        int count =0;\n        Arrays.sort(nums);\n        if(k==0)\n        {\n           int pre = 100000001;\n           for(int i=0;i<(n-1);i++)\n           {\n               if((nums[i]==nums[i+1]) && pre!=nums[i])\n               {\n                   count++;\n               }\n               pre = nums[i];\n           }\n           return count;\n        }\n        int pre = 100000001;\n        for(int i=0;i<n;i++)\n        {\n            if(pre!=nums[i])\n            {\n               count = count + search(nums,i,k,n-1);\n               pre = nums[i]; \n            }\n        }  \n        return count;\n    }\n    public int search(int[] nums,int l,int k,int r)\n    {\n        int target = nums[l];\n        int t = (target+k);\n        while(l<=r)\n        {\n            int mid = (l+r)/2;\n          \n            if(nums[mid]==t)\n            {\n                return 1;\n            }\n            else if(nums[mid]>t)\n            {\n                r = mid-1;\n            }\n            else\n            {\n                l = mid+1;\n            }\n            \n        }\n        return 0;\n    }\n}\n```
['Binary Tree', 'Java']