forked from Nandinig24/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1814
41 lines (34 loc) · 940 Bytes
/
1814
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Solution {
public:
#define MOD 1000000007
int countNicePairs(vector<int>& nums) {
// const long long mod=1000000007;
for(int i=0;i<nums.size();i++){
string s=to_string(nums[i]);
reverse(s.begin(),s.end());
int sum=stoi(s);
// cout<<sum<<" ";
nums[i]=nums[i]-sum;
}
vector<int> v;
sort(nums.begin(),nums.end());
int ans=nums[0];
int c=1;
for(int i=1;i<nums.size();i++){
if(nums[i]!=ans){
v.push_back(c);
ans=nums[i];
c=1;
}
else
c++;
}
v.push_back(c);
long long final=0;
for(int i=0;i<v.size();i++){
final+=((v[i]*1LL)*((v[i]-1)*1LL))/2;
}
int p=int(final%MOD);
return p;
}
};