code >>
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | class Solution { public:     int minAreaRect(vector<vector<int>>& points) {         int vecSize = (int)points.size();         unordered_map<int, set<int>> hashMap;         int result = 0;         int minArea = 1600000001;         int tempArea = 0;         int minx = 0;         int miny = 0;         int maxx = 0;         int maxy = 0;         for (const auto& point : points)         {             hashMap[point[0]].insert(point[1]);         }         for (int i = 0; i < vecSize; i++)         {             for (int j = i; j < vecSize; j++)             {                 minx = points[i][0];                 miny = points[i][1];                 maxx = points[j][0];                 maxy = points[j][1];                 if ((minx != maxx) && (miny != maxy))                 {// (minx,maxy) 가 존재하면서 동시에                  // (maxx,miny) 가 존재하면 직사각형을 만족한다.                     if (hashMap[minx].count(maxy) && hashMap[maxx].count(miny))                     {                         tempArea = (maxx - minx) * (maxy - miny);                         if (tempArea < 0)                             tempArea = -tempArea;                         if (minArea >= tempArea)                         {                             minArea = tempArea;                         }                     }                 }             }         }         if (minArea == 1600000001)             return 0;         else             return minArea;     } }; | 
'C' 카테고리의 다른 글
| c++ leetcode DP min cost climing stairs code (0) | 2021.07.26 | 
|---|---|
| c++ leetcode climbing stairs DP solution(Top-down and bottom-up) (0) | 2021.07.24 | 
| c++ leetcode 525 contiguous array solution (0) | 2021.07.24 | 
| c++ leetcode 380 Insert Delete GetRandom o(1) solution code (0) | 2021.07.17 | 
| c++ leetcode top-k frequent elements O(nlogn) solution (0) | 2021.07.16 |