Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from heapq import heappush,heappop
- class Solution:
- #Function to merge k sorted arrays.
- def mergeKArrays(self, arr, K):
- heap=[]
- for i in arr:
- heappush(heap,[i[0],0,i])
- ans=[]
- while len(heap)>0:
- k=heappop(heap)
- index=k[1]
- ar=k[2]
- ans.append(k[0])
- if len(ar)>index+1:
- heappush(heap,[ar[index+1],index+1,ar])
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement