c++ solution


  • 0
    W
    class Solution {
    public:
        int findPairs(vector<int>& nums, int k) {
            set<int> s;
            for (int i=0; i<nums.size(); ++i) {
                for (int j=i+1; j<nums.size(); ++j) {
                    int smaller = min(nums[i],nums[j]);
                    int bigger = max(nums[i],nums[j]);
                    if (bigger-smaller==k) {
                        s.insert(smaller);
                    }
                }
            }
            return s.size();
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.