旅游网站建设设计,开源网站建设是什么工作,wordpress 群聊汉化版插件,网站建设 印花税给你一个由一些多米诺骨牌组成的列表 dominoes。
如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌#xff0c;我们就认为这两张牌是等价的。
形式上#xff0c;dominoes[i] [a, b] 和 dominoes[j] [c, d] 等价的前提是 ac 且 bd#xff0c;或是…给你一个由一些多米诺骨牌组成的列表 dominoes。
如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌我们就认为这两张牌是等价的。
形式上dominoes[i] [a, b] 和 dominoes[j] [c, d] 等价的前提是 ac 且 bd或是 ad 且 bc。
在 0 i j dominoes.length 的前提下找出满足 dominoes[i] 和 dominoes[j] 等价的骨牌对 (i, j) 的数量。
示例
输入dominoes [[1,2],[2,1],[3,4],[5,6]] 输出1
代码
class Solution {public int numEquivDominoPairs(int[][] dominoes) {MapInteger,MapInteger,Integer mapnew HashMap();
//建立 小的元素 对 大的元素的映射int res0;for(int[] c:dominoes){int fMath.min(c[0],c[1]),s Math.max(c[0],c[1]);
//将每个数组的形式统一为 小的元素在前面MapInteger,Integer curmap.getOrDefault(f,new HashMap());if(cur.containsKey(s)){rescur.get(s); cur.put(s,cur.get(s)1);}else cur.put(s,1);map.put(f,cur);}return res;}
}