Simple Ruby Solution using sort


  • 0
    T

    This is probably cheating, but it's a really simple solution with good big O runtime (n log n) which is comparable to using a heap or mergesort.

    def merge_k_lists(lists)
      new_list = []
      lists.each do |list|
        while list != nil
          new_list << list.val
          list = list.next
        end
      end
      new_list.sort!
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.