clueless coding // TODO: be smarter

LeetCode Number of Boomerangs: CPP Solution



TL;DR Code Solution



double getDistance(pair<int, int> a, pair<int, int> b) {

    int dx = a.first - b.first;
    int dy = a.second - b.second;

    return dx*dx + dy*dy;

}

int numberOfBoomerangs(vector<pair<int, int>>& points) {

    int result = 0;

    for (int i = 0; i < points.size(); i++) {
        unordered_map<double, int> map;
        for (int j = 0; j < points.size(); j++) {
            if (i == j) continue;

            result += 2 * map[getDistance(points[i], points[j])]++;

        }

    }


    return result;

}