scala using PriorityQueue with O(n+k*log(n)) time


  • 0
    H
    def findKthLargest(nums: Array[Int], k: Int): Int = {
      val minHeap = new collection.mutable.PriorityQueue[Int]
      for(n <- nums) minHeap += n
      for(i <- 1 until k) minHeap.dequeue
      minHeap.dequeue
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.