Get different two results for same test case in my laptop and OJ


  • 0
    S

    I more willing to believe it is my mistake.

    test case:
    [3,5,5,6,9,1,4,5,0,5],
    [2,7,9,5,9,5,4,9,6,8],
    [6,0,7,8,1,0,1,6,8,1],
    [7,2,6,5,8,5,6,5,0,6],
    [2,3,3,1,0,4,6,5,3,5],
    [5,9,7,3,8,8,5,1,4,3],
    [2,4,7,9,9,8,4,7,3,7],
    [3,5,2,8,8,2,2,4,9,8]
    

    result in my local laptop is right, however, in OJ, result is

       [0,0,0,0,0,0,0,0,0,0],
        [2,0,9,5,0,*5*,4,9,0,8],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [5,0,7,3,0,8,5,1,0,3],
        [2,0,7,9,0,8,4,7,0,7],
        [3,0,2,8,0,2,2,4,0,8]]
    
    
    
    public class Solution {
        public void setZeroes(int[][] matrix) {
            boolean l0=false,c0=false;
            for(int i=0;i<matrix[0].length;i++){
            	l0|=(matrix[0][i]==0);
            }
    
            for(int i=0;i<matrix.length;i++){
            	c0|=(matrix[i][0]==0);
            }
    
            for(int x=1;x<matrix.length;x++){
            	for(int y=1;y<matrix[0].length;y++){
            		if(matrix[x][y]==0) {
            			matrix[x][0]=0;
            			matrix[0][y]=0;
            			break;
            		}
            	}
            }
    
            //set ZERO
            for(int i=1;i<matrix.length;i++){
            	for(int j=1;j<matrix[0].length;j++){
            		if(matrix[i][0]==0 || matrix[0][j]==0) matrix[i][j]=0;
            	}
            }
        
    
    
            if(l0) for(int i=0;i<matrix[0].length;i++) matrix[0][i]=0;
            if(c0) for(int i=0;i<matrix.length;i++) matrix[i][0]=0;
    
    
        }
    }

Log in to reply
 

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