Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- int rev(int x) {
- string s = to_string(x);
- reverse(s.begin(), s.end());
- x = stoi(s);
- return x;
- }
- public:
- int countNicePairs(vector<int>& nums) {
- unordered_map<int, int> ctr;
- for(int x : nums)
- ++ctr[x - rev(x)];
- const int mod = (int)1e9 + 7;
- int ans = 0;
- for(auto it : ctr)
- ans = (ans + it.second * (it.second - 1LL) / 2) % mod;
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement