там чел говорил что дело в отсутствие конструктора
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int moves[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
vector<vector<int>> wasThere;
Solution() : wasThere(301, {301}){};
//int wasThere[301][301];
void dfs(vector<vector<char>>& grid, int x, int y){
for(int i = 0; i < 4;i++){
int nx = x + moves[i][0];
int ny = y + moves[i][1];
if(nx < 0 nx >= grid.size() ny < 0 || ny >= grid[i].size()){
continue;
}
if(grid[nx][ny] == '1' && wasThere[nx][ny] != 1){
wasThere[nx][ny] = 1;
dfs(grid, nx, ny);
}
}
}
int numIslands(vector<vector<char>>& grid) {
int counter = 0;
for(int i = 0; i < grid.size();i++)
{
for(int j = 0; j < grid[i].size();j++){
if(grid[i][j] == '1' && wasThere[i][j] != 1){
counter++;
wasThere[i][j] = 1;
dfs(grid,i,j);
}
}
}
return counter;
}
};
int main()
{
vector<vector<char>> a = {
{'1','1','0','0','0'},
{'1','1','0','0','0'},
{'0','0','1','0','0'},
{'0','0','0','1','1'}
};
Solution b;
cout << b.numIslands(a);
}