题解 | 寻找第K大
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param a int整型一维数组
* @param n int整型
* @param K int整型
* @return int整型
*/
public int findKth (int[] a, int n, int K) {
// write code here
List<Integer> list= new ArrayList<>();
for(int i =0;i<a.length;i++){
list.add(a[i]);
}
list.stream().distinct().toArray();
Collections.sort(list);
return list.get(n-K);
}
}
