Advertisement
smj007

Untitled

Feb 18th, 2024
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. class Solution:
  2.     def findKthLargest(self, nums: List[int], k: int) -> int:
  3.  
  4.         minheap = []
  5.  
  6.         for num in nums:
  7.             heapq.heappush(minheap, num)
  8.  
  9.             if len(minheap) > k:
  10.                 heapq.heappop(minheap)
  11.  
  12.         return minheap[0]
  13.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement