본문 바로가기
Problem Solving/LeetCode

[LeetCode] 812. Largest Triangle Area - Java

by graycode 2026. 10. 18.

• 문제 링크

 

Largest Triangle Area - LeetCode

Can you solve this real interview question? Largest Triangle Area - Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be formed by any three different points. Answers within 10-5 o

leetcode.com

 

• 풀이 코드

public class Solution {

    public double largestTriangleArea(int[][] points) {
        double max = 0;
        for (int i = 0, n = points.length; i < n; i++)
            for (int j = i + 1; j < n; j++)
                for (int k = j + 1; k < n; k++)
                    max = Math.max(max, 0.5 * Math.abs(points[i][0] * (points[j][1] - points[k][1]) + points[j][0] * (points[k][1] - points[i][1]) + points[k][0] * (points[i][1] - points[j][1])));

        return max;
    }

}

댓글