• 33.0%

https://leetcode.com/problems/number-of-islands/?tab=Description

Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count 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.

helper函数中的向左遍历和向下遍历，不能省略

https://discuss.leetcode.com/topic/11589/dfs-and-bfs-in-c

DFS and BFS in C++

When we met a ‘1’, the answer add 1, we also need to search all ‘1’ which connected to it directly or indirectly, and change it to ‘0’. And we can use DFS or BFS to search.

DFS

BFS

https://discuss.leetcode.com/topic/13045/my-accepted-c-solution-may-be-trivial

My accepted c++ solution (may be trivial)

#### python

202ms, 15.49%, October 18, 2016

https://discuss.leetcode.com/topic/16749/7-lines-python-14-lines-java

7 lines Python, ~ 14 lines Java

Sink and count the islands.

Python Solution

Java Solution 1

Java Solution 2

#### java

https://discuss.leetcode.com/topic/13248/very-concise-java-ac-solution

Very concise Java AC solution

https://discuss.leetcode.com/topic/11590/simple-java-solution

Simple Java Solution

The algorithm works as follow:

1. Scan each cell in the grid.
2. If the cell value is ‘1’ explore that island.
3. Mark the explored island cells with ‘x’.
4. Once finished exploring that island, increment islands counter.

The arrays dx[], dy[] store the possible moves from the current cell. Two land cells [‘1’] are considered from the same island if they are horizontally or vertically adjacent (possible moves (-1,0),(0,1),(0,-1),(1,0)). Two ‘1’ diagonally adjacent are not considered from the same island.

https://discuss.leetcode.com/topic/20080/clear-easy-java-solution

Clear & Easy Java Solution

https://discuss.leetcode.com/topic/11705/simple-dfs-sulotion

Simple DFS sulotion

Dont need the extra space, and O(mn)