这是Leetcode200。问题陈述是: 给定二维地图“ 1”(土地)和“ 0”(水),计算岛屿的数量。岛屿被水包围,是通过水平或垂直连接相邻的土地而形成的。您可能会假设网格的所有四个边缘都被水包围了。
function showPopup() {
document.getElementById('yourimage').style.display = 'block';
}
showPopup(); // show modal image.
function closePopUp() {
document.getElementById('yourimage').style.display = 'none';
}
document.getElementById('yourimage').addEventListener('click', closePopUp); // hide modal image
输出:1
在尝试解决此问题时出现错误 引用绑定到类型为'std :: vector>'(stl_vector.h)的空指针
对于某些输入,我得到了正确的答案,但是总体而言,当我提交该输入时,我遇到了错误。如果有人可以帮助我,我将不胜感激。
11110
11010
11000
00000
答案 0 :(得分:1)
这三个语句的顺序错误
int n=grid.size();
int m=grid[0].size(); // <-- problem here
if(grid.size()==0 || grid[0].size()==0)
return 0;
应该是
if(grid.size()==0 || grid[0].size()==0)
return 0;
int n=grid.size();
int m=grid[0].size();
否则,当grid[0]
等于零时,访问grid.size()
时会崩溃。