- μ΅λν κ°λ
μ¬μ© (λ§μ΄λμ€)
- element κ°μ 리ν΄νλ κ±΄λ° μκ° indexμ κ°λ
μΌλ‘ μ°©κ°νμ
- answerλ₯Ό +1μ© μΉ΄μ΄νΈνλ€κ° 쑰건문μ λ§λ¬μ λ 리ν΄νλ νμμΌλ‘ ν΄μ€¬μλλ° κ·Έλ κ² νλ©΄ μ λμ§
Solution
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
Reference
Leave a comment