Published:
Updated:

  • μ΅œλŒ€νž™ κ°œλ… μ‚¬μš© (λ§ˆμ΄λ„ˆμŠ€)
  • element 값을 λ¦¬ν„΄ν•˜λŠ” 건데 μˆœκ°„ index의 κ°œλ…μœΌλ‘œ μ°©κ°ν–ˆμŒ
    • answerλ₯Ό +1μ”© μΉ΄μš΄νŠΈν•˜λ‹€κ°€ 쑰건문을 λ§Œλ‚¬μ„ λ•Œ λ¦¬ν„΄ν•˜λŠ” ν˜•μ‹μœΌλ‘œ ν•΄μ€¬μ—ˆλŠ”λ° κ·Έλ ‡κ²Œ ν•˜λ©΄ μ•ˆ λ˜μ§€


SolutionPermalink

import heapq
from typing import List


class Solution:
    def findKthLargest(self, nums: List[int], k: int) -> int:
        answer = 0

        heap = []
        for num in nums:
            heapq.heappush(heap, -num)

        for _ in range(k):
            answer = -heapq.heappop(heap)

        return answer


ReferencePermalink

Leave a comment