leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1814.cpp (480B)


      1 class Solution {
      2   public:
      3     int countNicePairs(const vector<int> &nums) const {
      4         static const int MOD = 1E9 + 7;
      5         unordered_map<int, int> count;
      6         int res = 0;
      7         for (const int n : nums) {
      8             a int rev = 0, tmp = n;
      9             do {
     10                 rev = (rev * 10) + tmp % 10;
     11             } while ((tmp /= 10) > 0);
     12             const int crnt = n - rev;
     13             res = (res + count[crnt]++) % MOD;
     14         }
     15 
     16         return res;
     17     }
     18 };