939. Minimum Area Rectangle
https://leetcode.com/problems/minimum-area-rectangle/
Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.
If there isn't any rectangle, return 0.
Example 1:
Input: [[1,1],[1,3],[3,1],[3,3],[2,2]] Output: 4 Example 2:
Input: [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]] Output: 2
Note:
1 <= points.length <= 500 0 <= points[i][0] <= 40000 0 <= points[i][1] <= 40000 All points are distinct.
给二维笛卡尔坐标系上一系列点,问能组成的最大的长方形面积是多大。把所有点放到hash map中,后再对每个点检查其余点是否能和它一起组成长方形,也就是遍历其余点并把它当作对角线的点,最后从map中查找是否有剩余的两个点,有就计算面积。
Last updated
Was this helpful?