Here is a neat DFS solution. The problem is that it gives me Runtime error for the testcase (in comments).

When I copy the test case and run it in "custom testcase" it runs fine. Anyone could point out what happened?

```
class Solution {
public:
void solve(vector<vector<char>>& board) {
for(int i = 0; i < board.size(); ++i){
for(int j = 0; j < board[0].size(); ++j){
if(i == 0 || j == 0 || i + 1 == board.size() || j + 1 == board[0].size())
dfs(board, i, j);
}
}
for(int i = 0; i < board.size(); ++i){
for(int j = 0; j < board[0].size(); ++j){
if(board[i][j] == 'O')board[i][j] = 'X';
if(board[i][j] == '*')board[i][j] = 'O';
}
}
}
void dfs(vector<vector<char>> &board, int i, int j){
if(i >= board.size() || i < 0 || j >= board[0].size() || j < 0)
return;
if(board[i][j] == 'O'){
board[i][j] = '*';
dfs(board, i + 1, j);
dfs(board, i, j + 1);
dfs(board, i - 1, j);
dfs(board, i, j - 1);
}
return;
}
};```
```