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....
分类:
其他好文 时间:
2015-04-09 10:41:17
阅读次数:
185
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 assum...
分类:
其他好文 时间:
2015-04-09 08:56:29
阅读次数:
133
这一题运用广度优先搜索可以解决,主要是各个状态的转移以及某个状态出现过要标记,避免重复,进入死循环。
下面是AC代码,上面有详细的讲解:
# include
# include
# include
using namespace std;
class data //队列的结点,
{
public:
int water[3]; ...
分类:
其他好文 时间:
2015-04-09 08:53:22
阅读次数:
118
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 assum...
分类:
其他好文 时间:
2015-04-09 08:49:41
阅读次数:
134
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie...
分类:
其他好文 时间:
2015-04-09 06:08:10
阅读次数:
147
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 ...
分类:
其他好文 时间:
2015-04-09 00:59:17
阅读次数:
146
描述:Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 =0&&py>=0&&px<n&&py...
分类:
编程语言 时间:
2015-04-08 21:11:23
阅读次数:
189
原题链接:https://leetcode.com/problems/number-of-islands/题意描述:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is...
分类:
其他好文 时间:
2015-04-08 21:09:58
阅读次数:
131
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), desi...
分类:
其他好文 时间:
2015-04-08 18:16:49
阅读次数:
131
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A = [1,1,1,2,2,3],
Your function should return length = 5, and A is now [1,1,2,...
分类:
其他好文 时间:
2015-04-08 18:08:31
阅读次数:
118