# 976.Largest Perimeter Triangle

**976.Largest Perimeter Triangle**

难度:Easy

> 给定由一些正数（代表长度）组成的数组 A，返回由其中三个长度组成的、面积不为零的三角形的最大周长。

如果不能形成任何面积不为零的三角形，返回 0。

```
示例 1：

输入：[2,1,2]
输出：5
示例 2：

输入：[1,2,1]
输出：0
示例 3：

输入：[3,2,3,4]
输出：10
示例 4：

输入：[3,6,2,3]
输出：8
 

提示：

3 <= A.length <= 10000
1 <= A[i] <= 10^6
```

保证三条边能围成三角形即可,两边之和大于第三边.

```
class Solution {
public:
    int largestPerimeter(vector<int>& A) {
        sort(A.begin(), A.end());
        int len=A.size();
        for(int i=1;i<len-1;i++)
        if( A[len-i-2] + A[len-i-1] > A[len -i])  return A[len-i-1]+A[len-i-2]+A[len-i];

        return 0;
    }
};
```

> 执行用时 : 68 ms, 在Largest Perimeter Triangle的C++提交中击败了84.63% 的用户 内存消耗 : 10.5 MB, 在Largest Perimeter Triangle的C++提交中击败了73.24% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/976.largest_perimeter_triangle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
