How can I sort numbers lexicographically?

前端 未结 14 916
半阙折子戏
半阙折子戏 2020-12-09 04:56

Here is the scenario.

I am given an array \'A\' of integers. The size of the array is not fixed. The function that I am supposed to write may be called once with an

14条回答
  •  攒了一身酷
    2020-12-09 05:42

    Possible optimization: Instead of this:

    I converted each integer to its string format, then added zeros to its right to make all the integers contain the same number of digits

    you can multiply each number by (10^N - log10(number)), N being a number larger than log10 of any of your numbers.

提交回复
热议问题