1 parent bfc4b77 commit f685179Copy full SHA for f685179
1 file changed
leetcode3/이진희/1329. Sort the Matrix Diagonally.java
@@ -0,0 +1,27 @@
1
+import java.util.*;
2
+
3
+class Solution {
4
+ public int[][] diagonalSort(int[][] mat) {
5
+ int m = mat.length;
6
+ int n = mat[0].length;
7
8
+ Map<Integer, PriorityQueue<Integer>> map = new HashMap<>();
9
10
+ for (int i=0; i<m; i++) {
11
+ for (int j=0; j<n; j++) {
12
+ int key = i-j;
13
+ map.putIfAbsent(key, new PriorityQueue<>());
14
+ map.get(key).add(mat[i][j]);
15
+ }
16
17
18
19
20
21
+ mat[i][j] = map.get(key).poll();
22
23
24
25
+ return mat;
26
27
+}
0 commit comments