Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minAreaRect(vector<vector<int>>& points) {
- int res = INT_MAX;
- unordered_map<int, bool> mp;
- for(const auto& point : points)
- mp[getHash(point[0], point[1])] = true;
- for(int i=0; i<points.size()-1; i++){
- for(int j=i+1; j<points.size(); j++){
- if(points[i][0] == points[j][0] || points[i][1] == points[j][1])
- continue;
- if(mp[getHash(points[i][0], points[j][1])] && mp[getHash(points[j][0], points[i][1])])
- res = min(res, abs(points[i][0] - points[j][0]) * abs(points[i][1] - points[j][1]));
- }
- }
- if(res == INT_MAX)
- return 0;
- return res;
- }
- int getHash(int x, int y){
- return x*40001+y;
- }
- };
- -----------------------------
- class Solution {
- public:
- int minAreaRect(vector<vector<int>>& points) {
- unordered_map<int, unordered_set<int>> mp;
- int res = INT_MAX;
- for(const auto& point : points)
- mp[point[0]].insert(point[1]);
- for(int i=0; i<points.size()-1; i++){
- for(int j=i+1; j<points.size(); j++){
- if(points[i][0] == points[j][0] || points[i][1] == points[j][1])
- continue;
- if(mp[points[i][0]].count(points[j][1]) && mp[points[j][0]].count(points[i][1]))
- res = min(res, abs(points[i][0] - points[j][0]) * abs(points[i][1] - points[j][1]));
- }
- }
- if(res == INT_MAX)
- return 0;
- return res;
- }
- };
Add Comment
Please, Sign In to add comment