首页
Java
登录
6mi
u
盘
搜
搜 索
Java
最小的K个数
最小的K个数
xiaoxiao
2021-02-28
141
输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4。
<?php
function
GetLeastNumbers_Solution
(
$input
,
$k
)
{
// write code here
if
(
$k
>count(
$input
)){
return
array
(); } sort(
$input
);
//切片
return
array_slice(
$input
,
0
,
$k
); }
转载请注明原文地址: https://www.6miu.com/read-39895.html
技术
最新回复
(
0
)