Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.

You must do it in place.

&nbsp;
Example 1:

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]


Example 2:

Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]


&nbsp;
Constraints:


	m == matrix.length
	n == matrix[0].length
	1 &lt;= m, n &lt;= 200
	-231 &lt;= matrix[i][j] &lt;= 231 - 1


&nbsp;
Follow up:


	A straightforward solution using O(mn) space is probably a bad idea.
	A simple improvement uses O(m + n) space, but still not the best solution.
	Could you devise a constant space solution?


class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        rows = len(matrix)
        cols = len(matrix[0])
        visited=set()
        for r in range(rows):
            for c in range(cols):
                
                if matrix[r][c]==0 and (r,c) not in visited :
                    for t in range(cols):
                        if matrix[r][t]!=0:
                            matrix[r][t]=0
                            visited.add((r,t))
                    for h in range(rows):
                        if matrix[h][c]!=0:
                            matrix[h][c]=0
                            visited.add((h,c))
        ##Time Complexity :- O(m*n)
        ##Space Complexity:- O(m+n)
		
		```
class Solution {
    public void setZeroes(int[][] matrix) {        
		if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
			return;

		int row = matrix.length;
		int col = matrix[0].length;

		boolean firstColumnZero = false;
		boolean firstRowZero = false;

		// Check if first column should be made zero
		for (int i = 0; i < row; i++) {
			if (matrix[i][0] == 0) {
				firstColumnZero = true;
				break;
			}
		}

		// Check if first row should be made zero
		for (int i = 0; i < col; i++) {
			if (matrix[0][i] == 0) {
				firstRowZero = true;
				break;
			}
		}

		// Traverse the matrix excluding first row and column
		// If zero is found, update the same in first row and column

		for (int i = 1; i < row; i++) {
			for (int j = 1; j < col; j++) {
				if (matrix[i][j] == 0) {
					matrix[i][0] = 0;
					matrix[0][j] = 0;
				}
			}
		}

		// Now traverse again and update
		for (int i = 1; i < row; i++) {
			for (int j = 1; j < col; j++) {
				if (matrix[i][0] == 0 || matrix[0][j] == 0) {
					matrix[i][j] = 0;
				}
			}
		}

		// Traverse and update first column
		if (firstColumnZero) {
			for (int i = 0; i < row; i++) {
				matrix[i][0] = 0;
			}
		}

		// Traverse and update first row
		if (firstRowZero) {
			for (int j = 0; j < col; j++) {
				matrix[0][j] = 0;
			}
		}

	
    }
}
class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        unordered_map<int,int>ump;
        unordered_map<int,int>mp;
        for(int i=0;i<matrix.size();i++){
            for(int j=0;j<matrix[0].size();j++){
                if(matrix[i][j]==0){
                    ump[i]=1;
                    mp[j]=1;
                }
            }
        }
        for(int i=0;i<matrix.size();i++){
            for(int j=0;j<matrix[0].size();j++){
                if(ump[i] || mp[j]){
                    matrix[i][j]=0;
                }
            }
        }


        
        
    }
};
var setZeroes = function(matrix) {
let rows = new Array(matrix.length).fill(0); //to store the index of rows to be set to 0
let cols = new Array(matrix[0].length).fill(0);//to store the index of columns to be set to 0
for(let i=0; i<matrix.length; i++){
    for(let j=0; j<matrix[i].length; j++){
        if(matrix[i][j]===0){//for zero value both row and column will be set to 0
            rows[i] = 1;
            cols[j] = 1;
        }
    }
}

for(let i=0; i<matrix.length; i++){
    for(let j=0; j<matrix[i].length; j++){
        if(rows[i]===1 || cols[j]===1){//if either row or col val is set, poulate it with 0
            matrix[i][j] = 0;
        }
    }
}
};
Set Matrix Zeroes