[문제]
https://leetcode.com/problems/array-partition-i/\
3Sum - LeetCode
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.com
주어진 배열의 페어 중 작은값을 더했을 때 가장 큰 답을 갖는걸 찾는 문제.
[답1]
class Solution:
def arrayPairSum(self, nums: List[int]) -> int:
answer = 0
nums.sort()
for i, n in enumerate(nums) :
if i % 2 is 0 :
answer += n
return a
[결과]
Runtime: 264 ms, faster than 68.02% of Python3 online submissions for Array Partition I.
Memory Usage: 16.9 MB, less than 12.47% of Python3 online submissions for Array Partition I.
[풀이]
- 매우 쉬운 문제이다. 오름차순으로 정렬을 했을 때 홀수번째 값을 더하면 된다.
[교훈]
- 너무 쉬워서 없다.
'💻 Study > 🧩 알고리즘' 카테고리의 다른 글
리트코드] 121. Best Time to Buy and Sell Stock (0) | 2022.05.19 |
---|---|
리트코드] 238. Product of Array Except Self (0) | 2022.05.18 |
리트코드] 15. Three Sum (0) | 2021.07.05 |
리트코드] 1. Two Sum (0) | 2021.07.01 |
리트코드] 1. Two Sum (0) | 2021.06.30 |