# Heeelp!! I got Runtime Error when I submitted my code, but it's right while I run the code online with the test case..

• ``````class Solution {
public:
vector<vector<int>> visit;
void solve(vector<vector<char>>& board) {
if(board.size()==0||board[0].size()==0)return;
visit = vector<vector<int>>(board.size(),vector<int>(board[0].size(),0));
int count=0;
for(int i=0;i<board.size();i++)
for(int j=0;j<board[0].size();j++){
if(visit[i][j]!=0||board[i][j]=='X')
continue;
count++;
if(dfs(board,i,j,count)){
for(int m=0;m<board.size();m++)
for(int n=0;n<board[0].size();n++)
if(visit[m][n]==count)
board[m][n]='X';
}
}
}

bool dfs(vector<vector<char>>& board,int i,int j,int ff){
bool flag = true;
for(int p=-1;p<=1;p++)
for(int q=-1;q<=1;q++){
if(p+q!=-1&&p+q!=1)continue;
if(i+p<0||j+q<0||i+p>=board.size()||j+q>=board[0].size())continue;
if(board[i+p][j+q]=='X')continue;
if(visit[i+p][j+q]!=0)continue;
visit[i+p][j+q]=ff;
flag=dfs(board,i+p,j+q,ff);
if(i+p==0||j+q==0||i+p==board.size()-1||j+q==board[0].size()-1)
flag=false;
}
return flag;
}
};``````

• I guess that test machine ran out of memory when many test cases were running in parallel. I tried stack-based DFS and problem went away.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.