1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public int countPairs(List<List<Integer>> coordinates, int k) { long res = 0; Map<Long, Integer> map = new HashMap<>(); for (List<Integer> arr : coordinates) { int x = arr.get(0), y = arr.get(1); for (int i = 0; i <= 100; ++i) { long t1 = x ^ i, t2 = y ^ (k - i); res += map.getOrDefault((t1 << 32) | t2, 0); } long key = ((long) x << 32) | y; map.put(key, map.getOrDefault(key, 0) + 1); } System.out.println(); return (int) res; }
}
|