C++简单代码/2行:

class Solution {
public:
    vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
        sort(input.begin(), input.end());
        return (k > input.size()) ? vector<int> {} : vector<int> (input.begin(), input.begin() + k);
    }
};