본문 바로가기
python-algorithm

Leetcode 561. Array Partition I

by 무적김두칠 2021. 8. 26.

1
2
3
4
5
6
7
class Solution:
    def arrayPairSum(self, nums: List[int]) -> int:
        nums.sort()
        ans=0
        for i in range(0,len(nums),2):
            ans+=nums[i]
        return ans
cs

원래는 그리디알고리즘으로 찾는게 맞는데..
규칙이 보여서 쉽게 구현했습니다

반응형

'python-algorithm' 카테고리의 다른 글

백준 9237 이장님 초대  (0) 2021.08.26
Leetcode 1877. Minimize Maximum Pair Sum in Array  (0) 2021.08.26
백준 2828 사과 담기 게임  (0) 2021.08.25
백준 2108 통계학  (0) 2021.08.24
백준 10773 제로  (0) 2021.08.24

댓글