200. Number of Islands

Given an m x n 2d grid map of '1's (land) and '0's (water), return the number of islands.

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

Example 1:

Example 2:

加上座標的話, 更清楚

use visited, dont modify origin grid value(no flood fill)

因為在某些題目是不能改值的 , 這時候還是要用 visited 來標記走過了

使用 visited,

Last updated

Was this helpful?