Leetcode 1018 Solution
This article provides solution to leetcode question 1018 (largest-perimeter-triangle)
Access this page by simply typing in "lcs 1018" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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