week01/LeetCode_1254/Solution_momo262_v0.java
//travel from 0,until no more connected 0s
travel from 0,until no more connected 0s
travel from 0 until no more connected 0s
private void travel(int[][] grid,int rowIndex,int columnIndex) {
        if (grid[rowIndex][columnIndex] == 1) {
            return;
        }
        grid[rowIndex][columnIndex] = 1;
        if (rowIndex > 0) {
            travel(grid,rowIndex - 1,columnIndex);
        }
        if (rowIndex < grid.length - 1) {
            travel(grid,rowIndex + 1,columnIndex);
        }
        if (columnIndex > 0) {
            travel(grid,rowIndex,columnIndex -1);
        }
        if (columnIndex < columnNumber - 1) {
            travel(grid,rowIndex,columnIndex + 1);
        }
    }
private void travel ( int [ ] [ ] grid , int rowIndex , int columnIndex ) { if ( grid [ rowIndex ] [ columnIndex ] == 1 ) { return ; } grid [ rowIndex ] [ columnIndex ] = 1 ; if ( rowIndex > 0 ) { travel ( grid , rowIndex - 1 , columnIndex ) ; } if ( rowIndex < grid . length - 1 ) { travel ( grid , rowIndex + 1 , columnIndex ) ; } if ( columnIndex > 0 ) { travel ( grid , rowIndex , columnIndex - 1 ) ; } if ( columnIndex < columnNumber - 1 ) { travel ( grid , rowIndex , columnIndex + 1 ) ; } }
travel from 0,until no more connected 0s
travel from 0 until no more connected 0s
//set to 1,mark as travelled //travel up //travel down //travel left //travel right