Skip to content

Commit b0d78bc

Browse files
committed
0422
1 parent 0e94894 commit b0d78bc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

C++/面试题40 最小的K个数.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
vector<int> getLeastNumbers(vector<int>& arr, int k) {
4+
vector<int> ret;
5+
priority_queue<int, vector<int>, greater<int> > pq;
6+
for(auto item: arr) pq.push(item);
7+
while(k--) {
8+
ret.push_back(pq.top());
9+
pq.pop();
10+
}
11+
return ret;
12+
}
13+
};

0 commit comments

Comments
 (0)