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 71a3cbd commit 31fe582Copy full SHA for 31fe582
Swift/215. Kth Largest Element in an Array.swift
@@ -0,0 +1,7 @@
1
+// 215. Kth Largest Element in an Array
2
+// 20 ms, 97.33%
3
+func findKthLargest(_ nums: [Int], _ k: Int) -> Int {
4
+ if nums.isEmpty { return 0 }
5
+ let sn = nums.sorted(by: >)
6
+ return (k <= sn.count && k > 0) ? sn[k-1] : sn[0]
7
+}
0 commit comments