m1ndy5's coding blog

LeetCode 561. Array Partition with Python 본문

알고리즘 with python/알고리즘 스터디

LeetCode 561. Array Partition with Python

정민됴 2024. 1. 3. 17:35

https://leetcode.com/problems/array-partition/

class Solution:
    def arrayPairSum(self, nums: List[int]) -> int:
        nums.sort()
        answer = 0
        for i in range(0, len(nums), 2):
            answer += nums[i]
        return answer

큰 애들은 큰 애들이랑 붙어야 큰 애들이 많이 살아남을 거 같아서 정렬한 다음 짝수번째 인덱스 애들만 더했다!