leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0939.cpp (741B)
0 class Solution { 1 static int hash(int x, int y) { return 40000 * x + y; } 2 3 public: 4 int minAreaRect(const vector<vector<int>> &points) const { 5 const int n = size(points); 6 unordered_set<int> us; 7 int res = INT_MAX; 8 9 for (int i = 0; i < n; i++) { 10 for (int j = 0; j < i; j++) { 11 const int x1 = points[i][0], y1 = points[i][1]; 12 const int x2 = points[j][0], y2 = points[j][1]; 13 if (us.count(hash(x1, y2)) && us.count(hash(x2, y1))) { 14 res = min(res, abs(x1 - x2) * abs(y2 - y1)); 15 } 16 } 17 us.insert(hash(points[i][0], points[i][1])); 18 } 19 20 return res != INT_MAX ? res : 0; 21 } 22 };