Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

447. Number of Boomerangs #145

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { public int numberOfBoomerangs(int[][] points) { int sum = 0; for(int i = 0; i < points.length; i++) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int j = 0; j < points.length; j++) { if(i == j) continue; int dx = (points[i][0]-points[j][0]) (points[i][0]-points[j][0]); int dy = (points[i][1]-points[j][1]) (points[i][1]-points[j][1]); int distance = dx + dy; map.putIfAbsent(distance, 0); map.put(distance, map.get(distance) + 1); } for(int n : map.values()) { sum += n(n-1);//此处是排列组合,在现有的距离相等的点中,任取两个的所有情况是(Cn2 = n!/(n-2)! = nn-1) } }

    return sum;
}

}

Shawngbk commented 7 years ago

google