Number of Pairs of Interchangeable Rectangles LeetCode solution in C++
1class Solution {2public:3long long interchangeableRectangles(vector<vector<int>> &rectangles) {4int n = rectangles.size();5unordered_map<double, int> mp;6for (int i = 0; i < n; i++) {7double ratio = rectangles[i][0] / (double)rectangles[i][1];8mp[ratio]++;9}10long long count = 0;1112for (auto i : mp) {13long long x = i.second;14x = (x * (x - 1)) / 2.0;15count += x;16}17return count;18}19};