get indexes of n smallest elements in an array

前端 未结 6 1608
醉酒成梦
醉酒成梦 2020-12-17 08:15

I have an int array int[] myArray = new int[100]; and want to get indexes of smallest 10 (any n) elements. How can I do this?

6条回答
  •  轮回少年
    2020-12-17 08:51

    You can sort the array, loop the first 10 elements and then for each element search into the array which position it has... maybe it's not the more efficient way, but it's the easier one.

提交回复
热议问题