From 48f4961febc7d03056cd826682e4b3277c7b20ca Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 26 Sep 2025 21:08:43 -0600 Subject: 812. largest triangle area --- largest_triangle_area.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 largest_triangle_area.py (limited to 'largest_triangle_area.py') diff --git a/largest_triangle_area.py b/largest_triangle_area.py new file mode 100644 index 0000000..506586f --- /dev/null +++ b/largest_triangle_area.py @@ -0,0 +1,34 @@ +# 812. Largest Triangle Area +from itertools import combinations + +""" +given an array of points on the x-y plane 'points' where 'points[i] = [x_i, +y_i]' return the area of the largest triangle that can be formed by any three +different points. answers within 10^-5 will be accepted. +""" + + +class Solution(object): + def largestTriangleArea(self, points): + """ + :type points: List[List[int]] + :rtype: float + """ + return max( + 0.5 + * abs( + i[0] * j[1] + + j[0] * k[1] + + k[0] * i[1] + - j[0] * i[1] + - k[0] * j[1] + - i[0] * k[1] + ) + for i, j, k in combinations(points, 3) + ) + + +if __name__ == "__main__": + obj = Solution() + print(obj.largestTriangleArea(points=[[0, 0], [0, 1], [1, 0], [0, 2], [2, 0]])) + print(obj.largestTriangleArea(points=[[1, 0], [0, 0], [0, 1]])) -- cgit v1.2.3