How to sort an array efficiently

后端 未结 4 405
鱼传尺愫
鱼传尺愫 2021-01-28 01:46

I\'m trying to sort an array [3,3,2,1,3,2,2,2,1] to [1,1,3,3,3,2,2,2,2].

I\'m trying to handle it using object, using the number as key, and th

4条回答
  •  执笔经年
    2021-01-28 02:25

    Try something like

    var curIndex = 0;
    for i in result {
       arr.fill(i, curIndex, curIndex + result[i]);
       curIndex = curIndex + result[i];
    }
    

提交回复
热议问题