※ 引述 《argorok (死肥肥社管)》 之銘言:
:
: 1905. Count Sub Islands
:
: 給兩個grid 求grid2的islands中是grid1的sub island的數量
sub island :
當前island
全部的格子都在grid1的那個island裡面
只要超出去一個就不算
思路 :
一邊遍歷所有grid2的island
順便看當前island
有沒有全部跟grid1的island 重疊
然後加起來就好了
```cpp
class Solution {
public:
vector<vector<int>> paper;
void go(vector<vector<int>>& grid , int i , int j , int &jiwp)
{
if(i<0 || i>=grid.size() || j<0 || j>=grid[0].size())return;
if(grid[i][j]==0)return;
grid[i][j]=0;
if(paper[i][j]==0)jiwp = 0;
go(grid,i-1,j,jiwp);
go(grid,i+1,j,jiwp);
go(grid,i,j-1,jiwp);
go(grid,i,j+1,jiwp);
}
int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2)
{
paper = grid1;
int n = grid2.size();
int m = grid2[0].size();
int res = 0;
for(int i = 0 ; i < n ; i ++)
{
for(int j = 0 ; j < m ; j++)
{
if(grid2[i][j]==0)continue;
int jiwp = 1;
go(grid2,i,j,jiwp);
if(jiwp)res++;
}
}
return res;
}
};
```