###### Middle-题目39：73. Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

public class Solution {
public void setZeroes(int[][] matrix) {
int rows=matrix.length;
int cols=matrix[0].length;
boolean[] isZeroRow = new boolean[rows];
boolean[] isZeroCol = new boolean[cols];
for(int i = 0;i <rows;i++) {
for(int j = 0;j < cols;j++) {
if(matrix[i][j]==0) {
isZeroRow[i]=true;
isZeroCol[j]=true;
}
}
}
for(int i = 0;i<rows;i++) {
if(isZeroRow[i]) {
for(int j=0;j<cols;j++) {
matrix[i][j]=0;
}
}
}
for(int j=0;j<cols;j++) {
if(isZeroCol[j]) {
for(int i=0;i<rows;i++) {
matrix[i][j]=0;
}
}
}
}
}

void setZeroes(int** matrix, int matrixRowSize, int matrixColSize) {
int col0 = 0;
int row0 = 0;
for(int i = 0; i < matrixRowSize; i++) {
if(matrix[i][0] == 0) {
col0 = 1;
break;
}
}
for(int j = 0; j < matrixColSize; j++) {
if(matrix[0][j] == 0) {
row0 = 1;
break;
}
}
for(int i = 1;i < matrixRowSize; i++) {
for(int j = 1;j < matrixColSize; j++) {
if(matrix[i][j] == 0) {
matrix[i][0] = 0;
matrix[0][j] = 0;
}
}
}
for(int i = 1;i < matrixRowSize;i++) {
if(!matrix[i][0]) {
for(int j = 1;j < matrixColSize;j++) {
matrix[i][j]=0;
}
}
}
for(int j = 1;j < matrixColSize;j++) {
if(!matrix[0][j]) {
for(int i = 1;i < matrixRowSize;i++) {
matrix[i][j]=0;
}
}
}
if(col0) {
for(int i = 0; i < matrixRowSize; i++)
matrix[i][0] = 0;
}
if(row0) {
for(int j = 0; j < matrixColSize; j++)
matrix[0][j] = 0;
}
}

cmershen的碎碎念：

#### leetcode_question_73 Set Matrix Zeroes

2013-09-19 21:47:44

#### LeetCode 73 — Set Matrix Zeroes（C++ Java Python）

2014-04-01 18:27:43

#### [leetcode] 【数组】73. Set Matrix Zeroes

2016-05-28 11:42:42

#### LeetCode 73 Set Matrix Zeroes(Python详解及实现)

2017-08-05 18:09:35

#### LeetCode --- 73. Set Matrix Zeroes

2015-03-20 21:50:38

#### 【LEETCODE】73-Set Matrix Zeroes [Python]

2016-01-20 09:50:00

#### LeetCode-73. Set Matrix Zeroes

2016-04-17 22:46:42

#### 73. Set Matrix Zeroes(Python3)

2018-01-29 10:55:52

#### leetcode 73. Set Matrix Zeroes-矩阵置零|数组

2016-06-03 16:47:58

#### 【LeetCode】Set Matrix Zeroes 解题报告

2014-10-24 10:17:51

## 不良信息举报

Middle-题目39：73. Set Matrix Zeroes