Leetcode 976 Solution
This article provides solution to leetcode question 976 (minimum-area-rectangle)
Access this page by simply typing in "lcs 976" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/minimum-area-rectangle
Solution
class Solution(object):
def minAreaRect(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
s = {(pt[0], pt[1]) for pt in points}
ans = sys.maxsize
for pt1 in points:
for pt2 in points:
if not (pt1[0] < pt2[0] and pt1[1] < pt2[1]):
continue
if (pt1[0], pt2[1]) not in s:
continue
if (pt2[0], pt1[1]) not in s:
continue
ans = min(ans, (pt2[0] - pt1[0]) * (pt2[1] - pt1[1]))
return ans if ans != sys.maxsize else 0