my solution beats 98.0% in java


  • 0
    G

    public int numberOfBoomerangs(int[][] points) {
    int len=points.length;
    int distance=0;
    int count=0;
    Map<Integer,Integer> map=new HashMap<>();
    for(int i=0;i<len;i++){
    Map<Integer,Integer> map=new HashMap<>();
    for(int j=0;j<len;j++){
    if(i==j) continue;
    distance=(points[i][0]-points[j][0])(points[i][0]-points[j][0])+(points[i][1]-points[j][1])(points[i][1]-points[j][1]);
    if(!map.containsKey(distance)) map.put(distance,1);
    else{
    int temp=map.get(distance);
    count=count+temp*2;
    map.put(distance,++temp);
    }
    }
    map.clear();
    }
    return count;
    }


Log in to reply
 

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