2971. Find Polygon With the Largest Perimeter

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2971

class Solution:
    def largestPerimeter(self, nums: List[int]) -> int:
        nums.sort()
        s = list(accumulate(nums, initial=0))
        res = -1
        for k in range(3, len(nums) + 1):
            if s[k - 1] > nums[k - 1]:
                res = max(res, s[k])
        return res