[코테 풀이] Largest Local Values in a Matrix

시내·2024년 6월 10일
0

Q_2373) Largest Local Values in a Matrix

출처 : https://leetcode.com/problems/largest-local-values-in-a-matrix/

class Solution {
    public int[][] largestLocal(int[][] grid) {
        int[][] res = new int[grid.length - 2][grid.length - 2];
        int max = 0;
        int startCol = 0;
        int startRow = 0;
        for (int t = 0; t < (grid.length - 2) * (grid.length - 2); t++) {
            for (int c = startCol; c < startCol + 3; c++) {
                for (int r = startRow; r < startRow + 3; r++) {
                    if (max < grid[c][r]) {
                        max = grid[c][r];
                    }
                }
            }
            res[startCol][startRow] = max;
            max = 0;
            startRow++;

            if (startRow == grid.length - 1 - 1) {
                startCol++;
                startRow = 0;
            }
        }
        return res;
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글