Simple Java solution


  • 0
    public int numberOfBoomerangs(int[][] points) {
            if(points.length<3){ return 0;}
            int r=0;
            for(int i=0;i<points.length;i++){
                Map<Integer,Integer> map=new HashMap<>();
                for(int j=0;j<points.length;j++){
                    int d=(points[i][0]-points[j][0])*(points[i][0]-points[j][0])+(points[i][1]-points[j][1])*(points[i][1]-points[j][1]);
                    int count=map.getOrDefault(d,0);
                    map.put(d,count+1);
                    if(count>0){ r+=2*count;}
                }
            }
            return r;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.