rustgym/leetcode/
_812_largest_triangle_area.rs1struct Solution;
2
3impl Solution {
4 fn largest_triangle_area(points: Vec<Vec<i32>>) -> f64 {
5 let mut res: f64 = 0f64;
6 for i in &points {
7 for j in &points {
8 for k in &points {
9 let area = (i[0] * j[1] + j[0] * k[1] + k[0] * i[1]
10 - j[0] * i[1]
11 - k[0] * j[1]
12 - i[0] * k[1])
13 .abs();
14 let area = area as f64 / 2f64;
15 res = f64::max(area, res);
16 }
17 }
18 }
19 res
20 }
21}
22
23#[test]
24fn test() {
25 use assert_approx_eq::assert_approx_eq;
26 let points: Vec<Vec<i32>> = vec_vec_i32![[0, 0], [0, 1], [1, 0], [0, 2], [2, 0]];
27 assert_approx_eq!(Solution::largest_triangle_area(points), 2f64);
28}