Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 741 Bytes

32.md

File metadata and controls

35 lines (29 loc) · 741 Bytes
int mod=1e9 +7;
    int rev(int n)
    {
        int ans=0;
        while(n)
        {
            ans= ans*10 + n%10;
            n=n/10;
        }
        return ans;
    }
    int countNicePairs(vector<int>& nums) {
        
        unordered_map<int,int>m;
        int ans=0;

        for(int i=0;i<nums.size();i++)
        {
             nums[i]-=rev(nums[i]);
             m[nums[i]]++;
        }

        for(auto x: m)
        {

            cout<<x.first<<" : "<<x.second<<endl;
            ans = ans %mod + (((long)x.second*(long)(x.second-1))/2) % mod;;
        }

        return ans%mod;
    }