Works fine on my computer but always get wrong answer on OJ


  • 0
    M

    After I submit my code, I always get

    Input: ["XXX","XOX","XXX"]
    Output: ["XXX","XOX","XXX"]
    Expected: ["XXX","XXX","XXX"]

    But I've tested this case on my computer, it outputs correctly. What is wrong?
    Below is my code:

       public void solve(char[][] board) {
    		if (board == null || board.length == 0 || board[0].length == 0) {
    			return;
    		}    
    
    		boolean[][] mark = new boolean[board.length][board[0].length];
    		int rowLen = board.length;
    		int colLen = board[0].length;
    		for (int i = 0; i < rowLen; i++) {
    			for (int j = 0; j < colLen; j++) {
    				if (board[i][j] == '0') {
    					if (i == 0 || j == 0) {
    						mark[i][j] = true;
    					} else {
    						mark[i][j] = mark[i-1][j] || mark[i][j-1]; 
    					}
    				}
    			}
    		}
    
    		for (int i = rowLen - 1; i >= 0; i--) {
    			for (int j = colLen - 1; j >= 0; j--) {
    				if (board[i][j] == '0') { 
    					if (i == rowLen - 1 || j == colLen - 1) {
    						mark[i][j] = true;
    					} else {
    						mark[i][j] = mark[i][j] || mark[i+1][j] || mark[i][j+1];
    					}
    
    					if (!mark[i][j]) {
    						board[i][j] = 'X';
    					}
    				}
    			}
    		}
        }

Log in to reply
 

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