剑指offer——最小的K个数

最小的K个数

https://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf?tpId=13&tqId=11182&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

solution:



std:

class Solution {
public:
    vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
        vector<int> ans ;
        if(k > input.size())
            return ans ;
        sort(input.begin(),input.end());
        for(int i=0;i<k;i++)
            ans.push_back(input[i]);
        return ans ;
    }
};
剑指offer 文章被收录于专栏

使用语言c++(比较喜欢用c++写编程题,java写的不熟)

全部评论

相关推荐

给大家传递好运~
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
牛客48826091...:哥们胸肌挺好看
点赞 评论 收藏
分享
面我面我面我_秋招版:不是戈门,干哪来了,这就是java嘛
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务