문제
답안
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])