215. Kth Largest Element in an Array Medium
1/**
2 * [215] Kth Largest Element in an Array
3 *
4 * Given an integer array nums and an integer k, return the k^th largest element in the array.
5 * Note that it is the k^th largest element in the sorted order, not the k^th distinct element.
6 * You must solve it in O(n) time complexity.
7 *
8 * Example 1:
9 * Input: nums = [3,2,1,5,6,4], k = 2
10 * Output: 5
11 * Example 2:
12 * Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
13 * Output: 4
14 *
15 * Constraints:
16 *
17 * 1 <= k <= nums.length <= 10^5
18 * -10^4 <= nums[i] <= 10^4
19 *
20 */
21pub struct Solution {}
22
23// problem: https://leetcode.com/problems/kth-largest-element-in-an-array/
24// discuss: https://leetcode.com/problems/kth-largest-element-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
25
26// submission codes start here
27
28impl Solution {
29 pub fn find_kth_largest(nums: Vec<i32>, k: i32) -> i32 {
30 0
31 }
32}
33
34// submission codes end
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_215() {
42 }
43}
44
Back
© 2025 bowen.ge All Rights Reserved.