Diagonal Traverse II LeetCode solution in Python
1class Solution:2def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:3# sort the index of element4heap = list()5n = len(nums)6for i in range(n):7m = len(nums[i])8for j in range(m):9heapq.heappush(heap, [i + j, j, i])1011# append the element one by one12ans = []13while heap:14temp = heapq.heappop(heap)15ans.append(nums[temp[2]][temp[1]])16return ans