Stefan | ᕕ(◠ڼ◠)ᕗ says to 電訊台
class Solution: def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]: m, n = len(mat), len(mat[0]) def helper(): within_bound = lambda x, y: ((0 <= x < m) and (0 <= y < n)) for i in range(m-1, -1, -1): i_, j = i, 0 seq = [] while within_bound(i_, j): seq.append((i_, j)) i_, j = i_+1, j+1 yield seq for j in range(n-1, 0, -1): i, j_ = 0, j seq = [] while within_bound(i, j_): seq.append((i, j_)) i, j_ = i+1, j_+1 yield seq for seq in helper(): for (i,j),k in zip(seq, sorted([mat[i][j] for i,j in seq])): mat[i][j] = k return mat this took me two hour, how the fuck...