<p>You are given an array of points in the <strong>X-Y</strong> plane <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p>

<p>Return <em>the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes</em>. If there is not any such rectangle, return <code>0</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/03/rec1.JPG" style="width: 500px; height: 447px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
<strong>Output:</strong> 4
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/03/rec2.JPG" style="width: 500px; height: 477px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]
<strong>Output:</strong> 2
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= points.length &lt;= 500</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 4 * 10<sup>4</sup></code></li>
	<li>All the given points are <strong>unique</strong>.</li>
</ul>

#首先得到所有可能存在的矩形 然后再比较面积
#得到所有举行的方法是 两个for循环 Cn2组合所有的两两点 然后找有没有和这两个点横纵坐标恰好相反的点
#目的是判断有没有两个点和他们成对角线 因为它要横平竖直的 所以如果两点横纵坐标有一个相同就肯定没有对角线 直接skip


class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        #point_map ={}
        #list不能直接做key
        #for point in points:
        #    point_map[point] = True
        #这里其实可以直接用set set相当于dict的key
        point_map ={}
        for point in points:
            #把list变成元组 之前想错了是把元组和set当成一个东西了
            point_map[(point[0], point[1])] = True
        #这里建list也没必要 一个值就行了 剩一个logn small_area = float('inf')
        small_area = []
        for point1 in points:
            for point2 in points:#这里可以去掉跟自己比 类比昨天那个题 下次循环去掉第一个point1 remove+copy
                if point1[0] != point2[0] and point1[1] != point2[1]:
                    #if point_map[point1[0], point2[1]] and point_map[point2[0], point1[1]]:
                    #这个部分先用in来判别 显然复杂度太高 需要优化
                    #if [point1[0], point2[1]] in points and [point2[0], point1[1]] in points:
                    #不能直接point_map(point1[0], point2[1]) 因为如果这个key不存在会报错 只能用in
                    #这样看来存value确实毫无意义 这里用set会更好
                    if (point1[0], point2[1]) in point_map and (point2[0], point1[1]) in point_map:
                        small_area.append(abs((point1[0] - point2[0]) * (point1[1] - point2[1])))
        if small_area == []:
            return 0
        return min(small_area)


26400