# 仍然是利用min heap,但是存放的key为值,value为坐标
import heapq
class Solution:
# @param {int[][]} arrays k sorted integer arrays
# @return {int[]} a sorted array
def mergekSortedArrays(self, arrays):
pq = []
for r in range(len(arrays)):
if not arrays[r]:
continue
heapq.heappush(pq, (arrays[r][0], r, 0))
res = []
while pq:
currMin = heapq.heappop(pq)
res.append(currMin[0])
r = currMin[1]
c = currMin[2]
if c + 1 < len(arrays[r]):
heapq.heappush(pq, (arrays[r][c + 1], r, c + 1))
return res