param { number [ ] [ ] } grid return { number } function maxAreaOfIsland ( grid ) { const dx = [ 1 , - 1 , 0 , 0 ] ; const dy = [ 0 , 0 , - 1 , 1 ] ; let maxValue = 0 ; const rows = grid . length ; const columns = grid [ 0 ] . length ; const dfs = ( grid , x , y ) => { if ( x < 0 || x >= rows || y < 0 || y >= columns || grid [ x ] [ y ] === 0 ) { return 0 ; } let area = 1 ; grid [ x ] [ y ] = 0 ; for ( let i = 0 ; i < dx . length ; i ++ ) { area = area + dfs ( grid , x + dx [ i ] , y + dy [ i ] ) ; } return area ; } ; for ( let i = 0 ; i < rows ; i ++ ) { for ( let j = 0 ; j < columns ; j ++ ) { if ( grid [ i ] [ j ] === 1 ) { maxValue = Math . max ( maxValue , dfs ( grid , i , j ) ) ; } } } return maxValue ; } export { maxAreaOfIsland } ;