Skip to content

Commit a6eab9a

Browse files
authored
Merge pull request #51 from masx200/masx200-patch-1
https://leetcode-cn.com/problems/count-nice-pairs-in-an-array/
2 parents cadc4c2 + 92ad179 commit a6eab9a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode-cn.com/problems/count-nice-pairs-in-an-array/
53+
5254
https://leetcode-cn.com/problems/sentence-similarity-iii/
5355

5456
https://leetcode.cn/problems/min-max-game/

count-nice-pairs-in-an-array/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function countNicePairs(nums: number[]): number {
2+
3+
const MOD = 1000000007;
4+
let res = 0;
5+
const h = new Map<number,number>();
6+
for (const i of nums) {
7+
let temp = i, j = 0;
8+
while (temp > 0) {
9+
j = j * 10 + temp % 10;
10+
temp = Math.floor(temp / 10);
11+
}
12+
res = (res + (h.get(i - j) || 0)) % MOD;
13+
h.set(i - j, (h.get(i - j) || 0) + 1);
14+
}
15+
return res;
16+
};
17+
export default countNicePairs

0 commit comments

Comments
 (0)