Created
July 8, 2021 17:17
-
-
Save wohhie/14d235b2d3e2272c394c8e43ee4fbb17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int findKthLargestNumber(int[] arr, int k) { | |
| Queue<Integer> queue = new PriorityQueue<>((n1, n2) -> n1.compareTo(n2)); | |
| for(int n : arr){ | |
| queue.add(n); | |
| if (queue.size() > k){ | |
| queue.poll(); | |
| } | |
| } | |
| return queue.poll(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment