把数组排成最小的数 Posted on 2019-08-31 | In 剑指offer | | reads times 把数组排成最小的数题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。 将数字拼接成一个数,需要数字越大越排在低位,越小的数字排在高位,所以需要321的1排在尽量高的位置。 123456789101112function PrintMinNumber(numbers){ // write code here numbers.sort(function(s1,s2){ const n1=`${s1}${s2}` const n2=`${s2}${s1}` return n1>n2 }) let min='' numbers.forEach((i)=>min+=i); return min;} Post author: GoldMiner Xun Post link: https://goldminerxun.github.io/2019/08/31/%E5%89%91%E6%8C%87offer%20JavaScript%20%E7%89%88(32)/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.