注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
傻逼了,把一个n写成了m没找出来,然后 &&写成了||。。。60min扯了20min写了20min, go through了10min 还剩10min让我run没run出来。。。
估计跪了。
贴个对的代码。
// 1 1 1 1 1 0
// 1 0 1 0 0 1 i) => 2
// 1 0 1 0 0 1 ii) => 1
// 1 1 0 1 1 1
// write a library/class that provides two functions / methods
// i) count the number of 'islands' that the matrix has
// ii) count the number of 'lakes' that the matrix has i.e. connected clump of zeros that is entirely surrounded by a single island
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<vector<int>> grid;
int m, n;
Solution (vector<vector<int>> &v):grid(v) {
m = grid.size();
n = grid[0].size();
}
int count return dfs2(i-1, j, key) && dfs2(i+1, j, key) && dfs2(i, j-1, key) && dfs2(i, j+1, key);
}
};
int main() {
vector<vector<int>> grid = {
{1, 1, 1, 1, 1, 0},
{1, 0, 1, 0, 0, 1},
{1, 0, 1, 0, 0, 1},
{1, 1, 0, 1, 1, 1}
};
Solution s(grid);
cout << s.countIslands() << endl;
cout << s.countLakes() << endl;
return 0;
}
补充内容 (2015-10-27 08:32):
好吧,居然过了,白小哥真给力。。。直接onsite了。。。 |