Efficient way to convert Scala Array to Unique Sorted List

前端 未结 7 2045
长发绾君心
长发绾君心 2021-01-04 15:00

Can anybody optimize following statement in Scala:

// maybe large
val someArray = Array(9, 1, 6, 2, 1, 9, 4, 5, 1, 6, 5, 0, 6) 

// output a sorted list whic         


        
7条回答
  •  半阙折子戏
    2021-01-04 15:45

    I'm not in a position to measure, but some more suggestions...

    Sorting the array in place before converting to a list might well be more efficient, and you might look at removing dups from the sorted list manually, as they will be grouped together. The cost of removing 0's before or after the sort will also depend on their ratio to the other entries.

提交回复
热议问题