Skip to content

Commit c066269

Browse files
authored
Create Solution3.cpp
1 parent 72c1939 commit c066269

File tree

1 file changed

+17
-0
lines changed
  • solution/0200-0299/0215.Kth Largest Element in an Array

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int findKthLargest(vector<int>& nums, int k) {
4+
unordered_map<int, int> cnt;
5+
int m = INT_MIN;
6+
for (int x : nums) {
7+
++cnt[x];
8+
m = max(m, x);
9+
}
10+
for (int i = m;; --i) {
11+
k -= cnt[i];
12+
if (k <= 0) {
13+
return i;
14+
}
15+
}
16+
}
17+
};

0 commit comments

Comments
 (0)