812. Largest Triangle Area

标签: leetcode-java
20人阅读 评论(0) 收藏 举报
分类:

You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.

Example:
Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
Output: 2
Explanation: 
The five points are show in the figure below. The red triangle is the largest.

leetcode_812
Notes:

3 <= points.length <= 50.
No points will be duplicated.
-50 <= points[i][j] <= 50.
Answers within 10^-6 of the true value will be accepted as correct.

class Solution {
    public double largestTriangleArea(int[][] points) {
        int N = points.length;
        double ans = 0;
        for (int i = 0; i < N; ++i)
            for (int j = i+1; j < N; ++j)
                for (int k = j+1; k < N; ++k)
                    ans = Math.max(ans, area(points[i], points[j], points[k]));
        return ans;
    }

    public double area(int[] P, int[] Q, int[] R) {
        return 0.5 * Math.abs(P[0]*Q[1] + Q[0]*R[1] + R[0]*P[1]
                             -P[1]*Q[0] - Q[1]*R[0] - R[1]*P[0]);
    }
}
查看评论

[Leetcode] 812. Largest Triangle Area 解题报告

题目: You have a list of points in the plane. Return the area of the largest triangle that can be...
  • magicbean2
  • magicbean2
  • 2018-04-09 11:00:26
  • 98

【LeetCode】812. Largest Triangle Area 解题报告(Python)

【LeetCode】812. Largest Triangle Area 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/p...
  • fuxuemingzhu
  • fuxuemingzhu
  • 2018-04-09 16:58:07
  • 33

812. Largest Triangle Area

You have a list of points in the plane. Return the area of the largest triangle that can be formed b...
  • xdhc304
  • xdhc304
  • 2018-04-15 10:24:38
  • 20

【LeetCode】443. String Compression 解题报告

【LeetCode】443. String Compression 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/str...
  • fuxuemingzhu
  • fuxuemingzhu
  • 2018-01-27 21:11:12
  • 180

leetcode 812. Largest Triangle Area

leetcode 812. Largest Triangle Area 原题地址:https://leetcode.com/problems/largest-triangle-area/ ...
  • birdreamer
  • birdreamer
  • 2018-04-08 11:48:39
  • 18

Largest Rectangular Area in a Histogram

Leetcode 利用stack经典题Largest Rectangular Area in a Histogram
  • huruzun
  • huruzun
  • 2014-10-01 12:02:00
  • 1639

【LeetCode】728. Self Dividing Numbers 解题报告

【LeetCode】728. Self Dividing Numbers 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/...
  • fuxuemingzhu
  • fuxuemingzhu
  • 2018-01-13 19:03:03
  • 135

【九度OJ】题目1194:八进制 解题报告

【九度OJ】题目1194:八进制 解题报告标签(空格分隔): 九度OJ原题地址:http://ac.jobdu.com/problem.php?pid=1194题目描述:输入一个整数,将其转换成八进制...
  • fuxuemingzhu
  • fuxuemingzhu
  • 2017-03-06 20:38:53
  • 344

CF 6A Triangle (判断三角形)

A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input stand...
  • ccutsoft20144264
  • ccutsoft20144264
  • 2016-06-08 11:14:04
  • 430

POJ 1927 Area in Triangle

计算几何
  • SenyeLicone
  • SenyeLicone
  • 2017-03-01 20:49:48
  • 265
    个人资料
    持之以恒
    等级:
    访问量: 3万+
    积分: 6399
    排名: 4741
    最新评论