Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-03-18_15-15-20.png
45 KB
#medium

#N1329. Sort the Matrix Diagonally
problem link

#solution
class Solution {
public int[][] diagonalSort(int[][] mat) {
int m = mat.length; //3
int n = mat[0].length; //4

for(int k = 0; k < Math.min(m, n) ; k++){
for(int i = 1; i < m; ++i){
for(int j = 1; j < n; ++j){
if(mat[i][j] < mat[i-1][j-1]){
int temp = mat[i-1][j-1];
mat[i-1][j-1] = mat[i][j];
mat[i][j] = temp;
}
}
}
}

return mat;
}
}