Skip to content

Commit 57e8a98

Browse files
committed
Add solution #1128
1 parent f33aba9 commit 57e8a98

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,143 LeetCode solutions in JavaScript
1+
# 1,144 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -889,6 +889,7 @@
889889
1123|[Lowest Common Ancestor of Deepest Leaves](./solutions/1123-lowest-common-ancestor-of-deepest-leaves.js)|Medium|
890890
1124|[Longest Well-Performing Interval](./solutions/1124-longest-well-performing-interval.js)|Medium|
891891
1125|[Smallest Sufficient Team](./solutions/1125-smallest-sufficient-team.js)|Hard|
892+
1128|[Number of Equivalent Domino Pairs](./solutions/1128-number-of-equivalent-domino-pairs.js)|Easy|
892893
1137|[N-th Tribonacci Number](./solutions/1137-n-th-tribonacci-number.js)|Easy|
893894
1143|[Longest Common Subsequence](./solutions/1143-longest-common-subsequence.js)|Medium|
894895
1161|[Maximum Level Sum of a Binary Tree](./solutions/1161-maximum-level-sum-of-a-binary-tree.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1128. Number of Equivalent Domino Pairs
3+
* https://leetcode.com/problems/number-of-equivalent-domino-pairs/
4+
* Difficulty: Easy
5+
*
6+
* Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d]
7+
* if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino
8+
* can be rotated to be equal to another domino.
9+
*
10+
* Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and
11+
* dominoes[i] is equivalent to dominoes[j].
12+
*/
13+
14+
/**
15+
* @param {number[][]} dominoes
16+
* @return {number}
17+
*/
18+
var numEquivDominoPairs = function(dominoes) {
19+
const map = new Map();
20+
let result = 0;
21+
22+
for (const [a, b] of dominoes) {
23+
const key = Math.min(a, b) * 10 + Math.max(a, b);
24+
const count = map.get(key) || 0;
25+
result += count;
26+
map.set(key, count + 1);
27+
}
28+
29+
return result;
30+
};

0 commit comments

Comments
 (0)