728x90
https://leetcode.com/problems/find-polygon-with-the-largest-perimeter/
class Solution:
def largestPerimeter(self, nums: List[int]) -> int:
nums.sort()
res = -1
total = 0
for n in nums:
if total > n:
res = total + n
total += n
return res
once we sort all we have to do is iterate though left to right and check for maximum sum
728x90
'Algorithm > NeetCode' 카테고리의 다른 글
Sort Characters By Frequency (0) | 2024.11.26 |
---|---|
Sequential Digits (0) | 2024.11.25 |
Divide Array Into Arrays With Max Difference (0) | 2024.11.24 |
Minimum Number of Operations to Make Array Empty (0) | 2024.11.23 |
Convert an Array Into a 2D Array With Conditions (0) | 2024.11.22 |