Leetcode每日一题:22/05/15:三角形最大面积

给定包含多个点的集合,从其中取三个点组成三角形,返回能组成的最大三角形的面积。

class Solution {
    public double largestTriangleArea(int[][] points) {
        //鞋带公式???确定不是在考数学???
        double res = 0;
        int len = points.length;
        for (int i = 0; i < len - 2; i++) {
            for (int j = i + 1; j < len - 1; j++) {
                for (int k = j + 1; k < len; k++) {
                    double temp = (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]) * 0.5;
                    res = Math.max(res, Math.abs(temp));
                }
            }
        }
        return res;
    }
}
posted @ 2022-05-16 11:47  Arthurma  阅读(14)  评论(0编辑  收藏  举报