题目描述:
方法一:
class Solution: def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: a,s,m=[(0,0)],[nums[0][0]],len(nums) while a: b=[] for i,j in a: for ii,jj in (i+1,j),(i,j+1): if ii<m and jj<len(nums[ii]) and nums[ii][jj]!=-1: s.append(nums[ii][jj]) b.append((ii,jj)) nums[ii][jj]=-1 a=b return s
方法二:排序
class Solution: def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: ans = [] for i, l in enumerate(nums): for j, n in enumerate(l): ans.append((i + j, j, n)) ans.sort() return [a[2] for a in ans]