I used two int type variables to recorded zero position. But...


  • 0
    L

    But there is a magical mistake.
    I used a bit operation,but I got a WA at 154th test cases.
    if : l&1<<i ==1.It said the l th line should be 0
    there is my WA code:

     class Solution
    

    {
    public:
    void setZeroes(vector<vector<int> > &matrix)
    {
    int r=0,l=0;

    		for(int i=0;i<matrix.size();i++)
    			for(int j=0;j<matrix[i].size();j++)
    				if(matrix[i][j]==0)		
    				{
    					r|=1<<j;
    					l|=1<<i;
    				}
    		for(int i=0;i<matrix.size();i++)
    		{
    		    for(int j=0;j<matrix[i].size();j++)
    		        if(r&1<<j||l&1<<i)
    		            matrix[i][j]=0;
    		}	
    	}
    

    };

    Can someone tell me why,?thank you.

    Please forgive my poor English...


  • 0
    1

    r and l are both int variables, so they can use to mark a matrix size of 32x32 at most, but the size of matrix may be larger than 32x32.


Log in to reply
 

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