Leetcode 1018 Solution

This article provides solution to leetcode question 1018 (largest-perimeter-triangle)

https://leetcode.com/problems/largest-perimeter-triangle

Solution

class Solution(object):
    def largestPerimeter(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        A.sort()
        for i in range(len(A) - 3, -1, -1):
            if A[i + 2] < A[i] + A[i + 1]:
                return A[i] + A[i + 1] + A[i + 2]
        return 0