from itertools import combinations import numpy as np classSolution: deflargestTriangleArea(self, points: List[List[int]]) -> float: return max(abs(np.linalg.det(np.array([[x0,y0,1],[x1,y1,1],[x2,y2,1]]))) for (x0,y0),(x1,y1),(x2,y2) in combinations(points,3))/2
如果对行列式进行一下展开和合并,那么可以得到这样的代码。
1 2 3 4
from itertools import combinations classSolution: deflargestTriangleArea(self, points: List[List[int]]) -> float: return max(abs((x0-x2)*(y1-y2)-(x1-x2)*(y0-y2)) for (x0,y0),(x1,y1),(x2,y2) in combinations(points,3))/2