public void solve(char[][] board) {
        if (board.length == 0) {
            return;
        }
        boolean[][] visited = new boolean[board.length][board[0].length];
        boolean[][] gray = new boolean[board.length][board[0].length];

        for (int i = 0; i != board.length; i++) {
            for (int j = 0; j != board[i].length; j++) {
                if (!visited[i][j] && board[i][j] == 'O') {
                    Pos pos = new Pos(j, i);
                    boolean isSafe = false;
                    todo.add(pos);

                    while (!todo.isEmpty()) {
                        Pos ps = todo.get(0);
                        todo.remove(0);

                        visited[ps.y][ps.x] = true;
                        gray[ps.y][ps.x] = true;
                        curVisited.add(ps);
                        if (ps.isAtEdge(board)) {
                            isSafe = true;
                        }
                        todo.addAll(ps.validSurround(board, visited, gray));
                    }
                    if (!isSafe) {
                        for (Pos p : curVisited) {
                            board[p.y][p.x] = 'X';
                        }
                    }
                    curVisited.clear();
                }
            }
        }
    }