leetcode

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

commit38ccdc5bc4d31a232612bad96efe63fa9e345e46
parent8c0b864dd7b3a51ce9b72aab16f11704ede5a585
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateTue, 21 Nov 2023 19:08:54 +0000

Daily Problem

Diffstat:
AProblems/1814.cpp|++++++++++++++++++
MREADME.md|+

2 files changed, 19 insertions(+), 0 deletions(-)


diff --git a/Problems/1814.cpp b/Problems/1814.cpp

@@ -0,0 +1,18 @@

class Solution {
public:
int countNicePairs(const vector<int> &nums) const {
static const int MOD = 1E9 + 7;
unordered_map<int, int> count;
int res = 0;
for (const int n : nums) {
a int rev = 0, tmp = n;
do {
rev = (rev * 10) + tmp % 10;
} while ((tmp /= 10) > 0);
const int crnt = n - rev;
res = (res + count[crnt]++) % MOD;
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -735,6 +735,7 @@ for solving problems.

| 1802 | Medium | [Maximum Value at a Given Index in a Bounded Array](Problems/1802.cpp) |
| 1806 | Medium | [Minimum Number of Operations to Reinitialize a Permutation](Problems/1806.cpp) |
| 1807 | Medium | [Evaluate the Bracket Pairs of a String](Problems/1807.cpp) |
| 1814 | Medium | [Count Nice Pairs in an Array](Problems/1814.cpp) |
| 1817 | Medium | [Finding the Users Active Minutes](Problems/1817.cpp) |
| 1822 | Easy | [Sign of the Product of an Array](Problems/1822.cpp) |
| 1823 | Medium | [Find the Winner of the Circular Game](Problems/1823.cpp) |