We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cb93bed commit 72c1939Copy full SHA for 72c1939
solution/0200-0299/0215.Kth Largest Element in an Array/Solution3.java
@@ -0,0 +1,16 @@
1
+class Solution {
2
+ public int findKthLargest(int[] nums, int k) {
3
+ Map<Integer, Integer> cnt = new HashMap<>(nums.length);
4
+ int m = Integer.MIN_VALUE;
5
+ for (int x : nums) {
6
+ m = Math.max(m, x);
7
+ cnt.merge(x, 1, Integer::sum);
8
+ }
9
+ for (int i = m;; --i) {
10
+ k -= cnt.getOrDefault(i, 0);
11
+ if (k <= 0) {
12
+ return i;
13
14
15
16
+}
0 commit comments