Published on

Leetcode - 561. Array Partition I

Authors
  • avatar
    Name
    Indo Yoon
    Twitter
Table of Contents

문제

[Loading...

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

LeetCode

](https://leetcode.com/problems/array-partition-i/)

답안

class Solution:
    def arrayPairSum(self, nums: List[int]) -> int:
        sorted_nums = sorted(nums)

        return sum([num for idx, num in enumerate(sorted_nums) if not idx % 2])

좀더 간결하게

class Solution:
    def arrayPairSum(self, nums: List[int]) -> int:
        return sum(sorted(nums)[::2])