题解 | #寻找第K大#
寻找第K大
http://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
public:
int findKth(vector<int> a, int n, int K) {
// write code here
sort(a.begin(),a.end(),[](int a,int b) -> int {return a>b;});
return a[K-1];
}
};
使用lamda表达式匿名函数,一行代码就搞定,这是C++11一大特性,因其在调用是分配内存,调用完之后就会释放,不需要函数声明和定义,所以占用的内存会更少。