LeetCode 솔루션					분류
				
						[10/12] 976. Largest Perimeter Triangle
본문
Easy
2221301Add to ListShareGiven 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.
Example 1:
Input: nums = [2,1,2] Output: 5
Example 2:
Input: nums = [1,2,1] Output: 0
Constraints:
- 3 <= nums.length <= 104
- 1 <= nums[i] <= 106
Accepted
159,756
Submissions
292,223
				태그
				#Tesla			
			관련자료
- 
			링크
			댓글 1
					
			학부유학생님의 댓글
- 익명
- 작성일
					
										
					Runtime: 385 ms, faster than 50.28% of Python3 online submissions for Largest Perimeter Triangle.
Memory Usage: 15.4 MB, less than 91.63% of Python3 online submissions for Largest Perimeter Triangle.
				
													
								Memory Usage: 15.4 MB, less than 91.63% of Python3 online submissions for Largest Perimeter Triangle.
class Solution:
    def largestPerimeter(self, nums: List[int]) -> int:
        nums = sorted(nums)
        
        while len(nums)>=3 and nums[-1] >= nums[-2] + nums[-3]:
            nums.pop()
        
        return sum(nums[-3:]) if len(nums)>=3 else 0 
								 
							







