跳转至

2373. 矩阵中的局部最大值

题目描述

原题链接

题解

class Solution {
    public int[][] largestLocal(int[][] grid) {
        int n = grid.length;
        int[][] maxLocal = new int[n-2][n-2];
        for(int i = 0;i < n -2;i++){
            for(int j = 0;j < n -2;j++){
                maxLocal[i][j] = max(grid,i,j);
            }
        }
        return maxLocal;

    }
    //row,column为左上角的坐标
    public int max(int[][] grid,int row,int column){
        int max = 0;
        for(int i=row;i < row+3;i++){
            for(int j = column;j < column+3;j++){
                if(grid[i][j] > max){
                    max = grid[i][j];
                }
            }
        }
        return max;
    }
}