【发布时间】:2011-12-30 21:29:57
【问题描述】:
任何人都可以在 Scala 中优化以下语句:
// maybe large
val someArray = Array(9, 1, 6, 2, 1, 9, 4, 5, 1, 6, 5, 0, 6)
// output a sorted list which contains unique element from the array without 0
val newList=(someArray filter (_>0)).toList.distinct.sort((e1, e2) => (e1 > e2))
既然性能很关键,有没有更好的办法?
谢谢。
【问题讨论】:
标签: arrays list scala optimization sorting