[LeetCode] Largest Triangle Area

812. 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 of the actual answer will be accepted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

class Solution {
public:
double largestTriangleArea(vector<vector<int>>& points) {
double res = 0.;
for(int i = 0; i < points.size(); i++) for(int j = i + 1; j < points.size(); j++) for(int k = j + 1; k < points.size(); k++) {
long long x1 = points[j][0] - points[i][0];
long long y1 = points[j][1] - points[i][1];
long long x2 = points[k][0] - points[i][0];
long long y2 = points[k][1] - points[i][1];
res = max(res, abs(x1 * y2 - x2 * y1) * 0.5);
}
return res;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2025/09/27/PS/LeetCode/largest-triangle-area/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.