- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1128.java
22 lines (20 loc) · 740 Bytes
/
_1128.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
packagecom.fishercoder.solutions.secondthousand;
importjava.util.HashMap;
importjava.util.Map;
publicclass_1128 {
publicstaticclassSolution1 {
publicintnumEquivDominoPairs(int[][] dominoes) {
intm = dominoes.length;
Map<Integer, Integer> map = newHashMap<>();
intcount = 0;
for (inti = 0; i < m; i++) {
intsmaller = Math.min(dominoes[i][0], dominoes[i][1]);
intbigger = Math.max(dominoes[i][0], dominoes[i][1]);
intkey = smaller * 10 + bigger;
count += map.getOrDefault(key, 0);
map.put(key, map.getOrDefault(key, 0) + 1);
}
returncount;
}
}
}