LintCode

Nov. 5th

Number of islands

Des: 2D matrix
Solution:
1. iterate through all the elements of the 2D matrix
2.if v == 1 ->
bfs through the one hop neighbors of the vertex
if all the neightbors == 0
result + 1
if any one of the neighbors == 1
bfs the neighbor
result + 1
3.return the result

Quesiton:
1.如何确定一个2D matrix 的行数和列数? -> 使用vertex s作为起点, (s-1) / n = 行数, (s-1) % n = 列数
n = grid.length m = grid[0].length
2.如何遍历

原文地址:https://www.cnblogs.com/kong-xy/p/7791461.html