Skip to content

Commit bb20b35

Browse files
committed
Add code for leetcode 976.
1 parent d43cff2 commit bb20b35

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: leetcode-976/leetcode976.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
class Solution:
3+
def largestPerimeter(self, A: List[int]) -> int:
4+
if (len(A) < 3):
5+
return 0
6+
7+
A.sort(reverse=True)
8+
for i in range(len(A)-2):
9+
if A[i] < A[i+1] + A[i+2]: # Can build a triangle
10+
return A[i] + A[i+1] + A[i+2]
11+
return 0
12+
13+
# Below is testing
14+
sol = Solution()
15+
print(sol.largestPerimeter([4, 5, 2, 7]))

0 commit comments

Comments
 (0)