Skip to content

Commit ed108a5

Browse files
committed
Runtime: 64 ms (Top 66.67%) | Memory: 56.7 MB (Top 16.67%)
1 parent fc0109b commit ed108a5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Runtime: 64 ms (Top 66.67%) | Memory: 56.7 MB (Top 16.67%)
12
class Solution {
23
public double minAreaFreeRect(int[][] points) {
34
Map<Pair<Double, Double>, Map<Double, List<int[][]>>> map = new HashMap<>();
4-
5+
56
double res = Double.MAX_VALUE;
67
for (int i = 0; i < points.length; i++) {
78
int[] p1 = points[i];
@@ -15,10 +16,10 @@ public double minAreaFreeRect(int[][] points) {
1516
double dist2 = dist2(p1, p2);
1617
if (!map.get(pm).containsKey(dist2))
1718
map.get(pm).put(dist2, new ArrayList<>());
18-
19+
1920
// calculate area for each pair of p3/p4 and check min
20-
// Worst case is each pair has same mid point with same length
21-
// At worst case, below operation costs O(N)
21+
// Worst case is each pair has same mid point with same length
22+
// At worst case, below operation costs O(N)
2223
for (int[][] ps : map.get(pm).get(dist2)) {
2324
double d1 = dist2(p1, ps[0]);
2425
double d2 = dist2(p1, ps[1]);
@@ -27,11 +28,11 @@ public double minAreaFreeRect(int[][] points) {
2728
map.get(pm).get(dist2).add(new int[][]{p1, p2});
2829
}
2930
}
30-
31+
3132
return res == Double.MAX_VALUE ? 0 : res;
3233
}
33-
34+
3435
private double dist2(int[] p1, int[] p2) {
3536
return (p2[0]-p1[0])*(p2[0]-p1[0]) + (p2[1]-p1[1])*(p2[1]-p1[1]);
3637
}
37-
}
38+
}

0 commit comments

Comments
 (0)