Skip to content

Commit cdf624b

Browse files
authored
Create Solution3.go
1 parent c066269 commit cdf624b

File tree

1 file changed

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

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func findKthLargest(nums []int, k int) int {
2+
cnt := map[int]int{}
3+
m := -(1 << 30)
4+
for _, x := range nums {
5+
cnt[x]++
6+
m = max(m, x)
7+
}
8+
for i := m; ; i-- {
9+
k -= cnt[i]
10+
if k <= 0 {
11+
return i
12+
}
13+
}
14+
15+
}

0 commit comments

Comments
 (0)