How to Sort a 2D array?

后端 未结 4 541
面向向阳花
面向向阳花 2021-01-29 12:24

I need help with sorting 2D array. I\'ve got array with two rows

[5, 3, 4, 1, 2]
[10,20,30,40,50]

and I need to sort it to look like this:

4条回答
  •  庸人自扰
    2021-01-29 13:16

    Edit (after OP changed formulations):

    You may collect that all to Map and then sort it by keys. Collecting to Map is O(n) and you can get sorting for free using ordered Map implementation. Transposing looks more expensive to me

提交回复
热议问题