岛屿数量
分析:对于一个1来说,结果+1,并将它和与它联通的所有1翻转为0,循环一次返回结果
var numIslands = function (grid) {
let num = 0
if(grid.length && grid[0].length) {
let rows = grid.length-1
let colums = grid[0].length-1
function over(i, j) {
if(i<0 || j<0 || i>rows || j>colums) return
if(grid[i][j]=='1') {
grid[i][j] = 0
over(i-1,j)
over(i,j-1)
over(i+1,j)
over(i,j+1)
}
}
for(let i=0; i<rows; i++) {
for(let j=0; j<colums; j++){
if(grid[i][j]=='1'){
num++
over(i, j)
}
}
}
return num
}
}