타나기
타나기 월드
타나기
전체 방문자
오늘
어제
  • 분류 전체보기 (90)
    • ⚙️ Rust (20)
      • 👀 Tutorial (20)
    • 🗿 Embedded (11)
      • 🐧 OS for ARM (11)
    • 💻 Study (37)
      • 🧩 알고리즘 (37)
    • 🏄🏽‍♂️ Life (21)
      • 🍚 타나구루망 (20)
      • 💡 Light (1)

인기 글

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
타나기

타나기 월드

💻 Study/🧩 알고리즘

리트코드] 561. Array Partition I

2021. 7. 6. 22:04

[문제]
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
    '💻 Study/🧩 알고리즘' 카테고리의 다른 글
    • 리트코드] 121. Best Time to Buy and Sell Stock
    • 리트코드] 238. Product of Array Except Self
    • 리트코드] 15. Three Sum
    • 리트코드] 1. Two Sum
    타나기
    타나기
    #include<all>

    티스토리툴바