1329. Sort the Matrix Diagonally
Question
A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end. For example, the matrix diagonal starting from
mat[2][0], wherematis a6 x 3matrix, includes cellsmat[2][0],mat[3][1], andmat[4][2].Given an
m x nmatrixmatof integers, sort each matrix diagonal in ascending order and return the resulting matrix.
Solution
分别遍历数组的两条边。
按对角线顺序进行遍历,用列表记录访问过的数字。
排序列表后按对角线填入原数组。
Code
1 | class Solution { |
1329. Sort the Matrix Diagonally
https://xuanhe95.github.io/2022/08/27/1329-Sort-the-Matrix-Diagonally/
