What is "Output Limit Exceeded" error


  • 1
    J

    Why below C# code will have "Output Limit Exceeded"
    it should run just fine!!!

    public void Solve (char[,] board)
    		{
    			// if not suranding by X, there must be zero on the edge
    			// look for any zero start from 0 update them and their nebour zero to 1
    			// loop thru matrix, covert everything to X except 1, and convert 1 to 0
    
    			if (board.Length == 0)
    				return;
    
    			this.MarkOne (board);
    
    			for (int row = 0; row <= board.GetUpperBound (0); row++) {
    				for (int col = 0; col <= board.GetUpperBound (1); col++) {
    					if (board [row, col] == '1')
    						board [row, col] = 'O';
    					else if (board [row, col] == '0')
    						board [row, col] = 'X';
    				}
    			}
    		}
    
    		private void MarkOne (char[,] board)
    		{
    			int rows = board.GetUpperBound (0);
    			int cols = board.GetUpperBound (1);
    
    			for (int r = 0; r <= rows; r++) {
    				if (board [r, 0] == 'O') {
    					this.MarkOne (board, r, 0);
    				}
    
    				if (board [r, cols] == 'O') {
    					this.MarkOne (board, r, cols);
    				}
    			}
    
    			for (int c = 0; c <= cols; c++) {
    				if (board [0, c] == 'O') {
    					this.MarkOne (board, 0, c);
    				}
    
    				if (board [rows, c] == 'O') {
    					this.MarkOne (board, rows, c);
    				}
    			}
    		}
    
    		private void MarkOne (char[,] board, int x, int y)
    		{
    			if (x < 0 || x > board.GetUpperBound (0) || y < 0 || y > board.GetUpperBound (1) || board [x, y] != 'O')
    				return;
    
    			board [x, y] = '1';
    			this.MarkOne (board, x - 1, y);
    			this.MarkOne (board, x + 1, y);
    			this.MarkOne (board, x, y - 1);
    			this.MarkOne (board, x, y + 1);
    		}

Log in to reply
 

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