Largest Local Values in a Matrix

就是挨个找最大

class Solution {
    public int[][] largestLocal(int[][] grid) {
        int n = grid.length;
        int[][] res = new int[n - 2][n - 2];
        for(int i = 1; i < n - 1; i++) {
            for(int j = 1; j < n - 1; j++) {
                res[i - 1][j - 1] = val(grid,i,j);
            }
        }
        return res;
    }
    
    public int val(int[][] g, int a, int b) {
        int res = Integer.MIN_VALUE;
        for(int i = a - 1; i <= a + 1; i++){
            for(int j = b - 1; j <= b + 1; j++){
                res = Math.max(res, g[i][j]);
            }
        }
        return res;
    }
}