Counts "islands" of 1s in sea of 0s (2d array matrix)
The code seems correct. The only missing part is


  You may assume all four edges of the grid are all surrounded by water.


which means that numIslands may iterate

    for (int i = 1; i &lt; grid.length - 1; i++) {
        for (int j = 1; j &lt; grid[i].length - 1; j++) {


and do not bother destroyIsland with validating the surroundings.