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

前端 未结 26 1946
余生分开走
余生分开走 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

    resubmitted

    Python - 74 chars (counting whitespace and newlines)

    def m(i):
     y=[];x=sum(i,[])
     while x:n=min(x);y+=[n];x.remove(n)
     return y
    

    i is input as list of lists

    Usage:

    >>> m([[1,5],[6,3]])
    [1, 3, 5, 6]
    

提交回复
热议问题