当前位置:网站首页>Sword finger offer 40 Minimum number of K
Sword finger offer 40 Minimum number of K
2022-06-11 08:43:00 【zmm_ mohua】
The finger of the sword Offer 40. The smallest k Number
subject

Code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> getLeastNumbers(vector<int>& arr, int k) {
vector<int> res;
if(k == 0){
return res;
}
sort(arr.begin(), arr.end());
for(int i = 0; i < k; i++){
res.push_back(arr[i]);
}
return res;
}
int main(){
int n, k;
cin>>n>>k;
vector<int> arr(n);
vector<int> res;
for(int i = 0; i < n; i++){
cin>>arr[i];
}
res = getLeastNumbers(arr, k);
for(int j = 0; j < res.size(); j++){
cout<<res[j]<<" ";
}
return 0;
}
边栏推荐
- @Usage details of postconstruct, initializingbean and initmethod
- 剑指 Offer 62. 圆圈中最后剩下的数字
- Asynchronous notification mechanism of character device driver
- torch. Var (), sample variance, parent variance
- Web design and website planning assignment 11 game selection form
- Solve ('You must install pydot (`pip install pydot`) and install graphviz (see...) '‘ for plot_ model..
- Codeworks round 680 div2
- What is concurrent search set? Are you still worried about it? In fact, it is a problem of connected graph, which is not so difficult to understand
- ActiveMQ simple tutorial, suitable for beginners, learning notes yyds
- qiao-npms:获取npm包下载量
猜你喜欢

JS learning basics document Write write a line of text in the page

剑指 Offer 62. 圆圈中最后剩下的数字

不想项目失控?你需要用对项目管理工具

(the slow download speed of cifar10 in torchvision has been solved) how to download and use torchvision import

Idea pulls items from remote warehouse

Mongodb--- automatically delete expired data using TTL index

TRUNC in pytorch_ normal_ principle

Is the result too different from the goal? With the help of target management, you can reach the target accurately!

(resolved) typeerror: meshgrid() got an unexpected keyword argument 'indexing‘

盘它!用「飞项」轻松管理各类型项目
随机推荐
进程控制:进程等待(回收子进程)
XXL task executor calls local project
Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波
Disk format FAT32, exFAT, NTFS of [software tool]
Award winning survey | how Apache pulsar lived in 2022, you the final say
Solve notimplementederror: layer XX has arguments in`__ init__` and therefore must override `get_ config`
Redis6 entry-level tutorial. There are integration cases. You can directly see the integration cases. It is easy to get started
How to solve the MySQL deadlock problem? Recitation version
torch. Var (), sample variance, parent variance
Web design and website planning assignment 12 online registration form
项目实训-克隆门
B+超强树,带你知晓MySQL的底层是怎样的结构
mysql高级特性篇,可以多看看,应付面试
(resolved) the tqdm progress bar in the Jupiter notebook does not update and display in one line, but scrolls down to output
How to do a good job in project management? Learning these four steps is enough
Asynchronous notification mechanism of character device driver
leetcode - 739. 每日温度
Icml2022 article intéressant
Use of Excel to XML tool of TestLink
js 中 Map 和 Set 的用法及区别