package hashTable;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by cuixiaodao on 11/15/2017
 * for leetCode problem:
 * https://leetcode.com/problems/number-of-boomerangs/description/
 */

public class NumberOfBoomerangs {
    public int numberOfBoomerangs(int[][] points) {
        int res = 0;

        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < points.length; i++) {
            for (int j = 0; j < points.length; j++) {
                if (i == j)
                    continue;

                int d = getDistance(points[i], points[j]);
                map.put(d, map.getOrDefault(d, 0) + 1);
            }

            for (int val : map.values()) {
                res += val * (val - 1);
            }
            map.clear();
        }

        return res;
    }

    private int getDistance(int[] a, int[] b) {
        int dx = a[0] - b[0];
        int dy = a[1] - b[1];

        return dx * dx + dy * dy;
    }
}
@@ -236,16 +236,44 @@
 rangs %7B%0A
+    // %E7%9B%B8%E5%90%8C%E8%B7%9D%E7%A6%BB -%3E %E8%B7%9D%E7%A6%BB%E4%B8%BAkey,%E6%9E%84%E9%80%A0map%0A
     publ
@@ -994,8 +994,9 @@
 %0A    %7D%0A%7D
+%0A

add notes