Why the leetcode compiler still tells me Run time error when the visual studio has correct outpu?


  • 0
    S

    My code has correct output in visual studio but has run time error submitted in leetcode...Do not know why????

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

    };


Log in to reply
 

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