From fecf4d726654aa243418c4122861f2d127aa0734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Sat, 12 Sep 2026 23:53:18 +0900 Subject: [PATCH] Create 1329. Sort the Matrix Diagonally.java --- .../1329. Sort the Matrix Diagonally.java" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/1329. Sort the Matrix Diagonally.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/1329. Sort the Matrix Diagonally.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/1329. Sort the Matrix Diagonally.java" new file mode 100644 index 00000000..b91c22df --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/1329. Sort the Matrix Diagonally.java" @@ -0,0 +1,24 @@ +class Solution { + public int[][] diagonalSort(int[][] mat) { + int m = mat.length, n = mat[0].length; + Map> map = new HashMap<>(); + + // 1. 대각선별로 값 모으기 (key = row - col) + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + int key = i - j; + map.computeIfAbsent(key, k -> new PriorityQueue<>()).offer(mat[i][j]); + } + } + + // 2. 정렬된 값 다시 채워넣기 + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + int key = i - j; + mat[i][j] = map.get(key).poll(); + } + } + + return mat; + } +}