Karleb
Posted on
2373. Largest Local Values in a Matrix
May 12 solution
/** * @param {number[][]} grid * @return {number[][]} *//** * @param {number[][]} grid * @return {number[][]} */varlargestLocal=function(grid){constnRows=grid.length;constnCols=grid[0].length;letresult=newArray(nRows-2).fill().map(()=>newArray(nCols-2).fill(0));for(letrow=0;row<nRows-2;row++){for(letcol=0;col<nCols-2;col++){result[row][col]=findLargest(grid,row,col);}}returnresult;};functionfindLargest(grid,row,col){letbest=grid[row][col];for(leti=row;i<row+3;i++){for(letj=col;j<col+3;j++){best=Math.max(best,grid[i][j]);}}returnbest;}
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse