-
Notifications
You must be signed in to change notification settings - Fork 115
/
0939-MinimumAreaRectangle.cs
30 lines (26 loc) · 1.09 KB
/
0939-MinimumAreaRectangle.cs
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
//-----------------------------------------------------------------------------
// Runtime: 352ms
// Memory Usage:
// Link:
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace LeetCode
{
public class _0939_MinimumAreaRectangle
{
public int MinAreaRect(int[][] points)
{
var pointSet = new HashSet<int>();
foreach (var point in points)
pointSet.Add(40001 * point[0] + point[1]);
var result = int.MaxValue;
for (int i = 0; i < points.Length; i++)
for (int j = i + 1; j < points.Length; j++)
if (points[i][0] != points[j][0] && points[i][1] != points[j][1])
if (pointSet.Contains(40001 * points[i][0] + points[j][1]) && pointSet.Contains(40001 * points[j][0] + points[i][1]))
result = Math.Min(result, Math.Abs(points[i][0] - points[j][0]) * Math.Abs(points[i][1] - points[j][1]));
return result < int.MaxValue ? result : 0;
}
}
}