#include "map" class Solution { public: int findKth(vector<int> a, int n, int K) { map<int, int> pool; for (int i = 0; i < n; i++) { auto tmp = pool.find(a[i]); if (tmp == pool.end()) { //没有就添加 pool.insert({a[i],1}); } else { //有就添加 tmp->second += 1; } } auto inter = pool.begin(); int tem = 0; for (; inter != pool.end(); inter++) { tem += inter->second; if(tem>=(n-K+1)){ return inter->first; } } return 0; } };