比较巧妙的做法
c++代码
class Solution {
public:
vector<int> getLeastNumbers_Solution(vector<int> input, int k) {
vector<int> C;
int a = -1000;
set<int> m;
for (int i = 0 ; i < input.size() ; i ++)
{
m.insert(input[i]);
}
for (int i = 0 ; i < k ; i ++)
{
int s = (*(m.upper_bound(a)));
C.push_back(s);
a = s;
}
return C;
}
};