class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int rows = matrix.size();
int cols = matrix[0].size();
if (rows == 0 || cols == 0)
{
return;
}
vector<bool> row(rows, false);
vector<bool> col(cols, false);
for (int i = 0;i < rows;i++)
{
for (int j = 0;j < cols;j++)
{
if (matrix[i][j] == 0)
{
row[i] = true;
col[j] = true;
}
}
}
for (int i = 0;i < rows;i++)
{
for (int j = 0;j < cols;j++)
{
if (row[i] || col[j])
{
matrix[i][j] = 0;
}
}
}
}
};
LeetCode面试题 01.08. 零矩阵
最新推荐文章于 2022-11-22 18:44:13 发布