# 976. Largest Perimeter Triangle

#### Easy

***

Given an integer array `nums`, return *the largest perimeter of a triangle with a non-zero area, formed from three of these lengths*. If it is impossible to form any triangle of a non-zero area, return `0`.

&#x20;

**Example 1:**

<pre><code>Input: nums = [2,1,2]
<strong>Output:
</strong> 5
</code></pre>

**Example 2:**

<pre><code>Input: nums = [1,2,1]
<strong>Output:
</strong> 0
</code></pre>

&#x20;

**Constraints:**

* `3 <= nums.length <= 104`
* `1 <= nums[i] <= 106`

```python
class Solution:
    def largestPerimeter(self, nums: List[int]) -> int:
        nums = sorted(nums)[::-1]
        for index in range(len(nums)-2):
            if nums[index] < nums[index+1] + nums[index+2]:
                return nums[index] + nums[index+1] + nums[index+2]
        return 0
```
