leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1814.cpp (480B)
0 class Solution {
1 public:
2 int countNicePairs(const vector<int> &nums) const {
3 static const int MOD = 1E9 + 7;
4 unordered_map<int, int> count;
5 int res = 0;
6 for (const int n : nums) {
7 a int rev = 0, tmp = n;
8 do {
9 rev = (rev * 10) + tmp % 10;
10 } while ((tmp /= 10) > 0);
11 const int crnt = n - rev;
12 res = (res + count[crnt]++) % MOD;
13 }
15 return res;
16 }
17 };