forked from kamyu104/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargest-triangle-area.py
More file actions
23 lines (20 loc) · 844 Bytes
/
largest-triangle-area.py
File metadata and controls
23 lines (20 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Time: O(n^3)
# Space: O(1)
class Solution(object):
def largestTriangleArea(self, points):
"""
:type points: List[List[int]]
:rtype: float
"""
result = 0
for i in xrange(len(points)-2):
for j in xrange(i+1, len(points)-1):
for k in xrange(j+1, len(points)):
result = max(result,
0.5 * abs(points[i][0] * points[j][1] +
points[j][0] * points[k][1] +
points[k][0] * points[i][1] -
points[j][0] * points[i][1] -
points[k][0] * points[j][1] -
points[i][0] * points[k][1]))
return result