Code golf: combining multiple sorted lists into a single sorted list

前端 未结 26 1843
余生分开走
余生分开走 2020-12-29 12:42

Implement an algorithm to merge an arbitrary number of sorted lists into one sorted list. The aim is to create the smallest working programme, in whatever language you like.

26条回答
  •  生来不讨喜
    2020-12-29 13:12

    Haskell like (158, but more than 24 spaces could be removed.):

    mm = foldl1 m where
      m [] b = b
      m a [] = a
      m (a:as) (b:bs)
       | a <= b = a : m as (b:bs)
       | true   = b : m (a:as) bs
    

提交回复
热议问题