Easy AC java solution


  • 0
    A
    public int numberOfBoomerangs(int[][] points) {
            if(points == null || points.length==0){
                return 0;
            }
            int count =0;
            for(int i=0;i< points.length;i++){
                HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
                for(int j= 0;j<points.length;j++){
                    if(i !=j){
                        int dist = (points[i][1]-points[j][1])*(points[i][1]-points[j][1]) +(points[i][0]-points[j][0])*(points[i][0]-points[j][0]);
                        if(!map.containsKey(dist)){
                            map.put(dist,0);
                        }else{
                            int val = map.get(dist);
                            val=val+2;
                            map.put(dist,val);
                            count += val;
                        }
                    }
    
                }
            }
            return count;
        }

Log in to reply
 

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