【Leetcode】812. Largest Triangle Area

class Solution(object):

    def largestTriangleArea(self, points):

        """

        :type points: List[List[int]]

        :rtype: float

        """

        maxi = float('-inf')

        for i, j, k in itertools.combinations(points, 3):

            maxi = max(maxi, 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]))

        return maxi


1 从一堆点中选三个点,可以使用build-in函数,itertools.combinations(points, 3)

你可能感兴趣的:(【Leetcode】812. Largest Triangle Area)