diff options
author | Jack Sangdahl <[email protected]> | 2025-09-26 21:08:43 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-09-26 21:08:43 -0600 |
commit | 48f4961febc7d03056cd826682e4b3277c7b20ca (patch) | |
tree | c7b42172d3db06468f818923bd388dbc94a97168 /largest_triangle_area.py | |
parent | 23353c144ac9b158af7616dc46b636d53b73ce34 (diff) | |
download | leetcode-48f4961febc7d03056cd826682e4b3277c7b20ca.tar.gz leetcode-48f4961febc7d03056cd826682e4b3277c7b20ca.zip |
812. largest triangle area
Diffstat (limited to 'largest_triangle_area.py')
-rw-r--r-- | largest_triangle_area.py | 34 |
1 files changed, 34 insertions, 0 deletions
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]])) |