leetcodehot100 矩阵置零

额外使用一个boolean变量用来判断第一列是否为零。另外第一行除了第一个用来标记当前的列是否为零,第一列用来标记当前行是否标记为零

class Solution {

public void setZeroes(int\[\]\[\] matrix) {

boolean isAllZero = false;//判断第一列是否存在零

for(int i = 0;i<matrix.length;i++){//将记录所有应该置零的地方

for(int j = 0;j<matrix0.length;j++){

if(matrixij==0){

if(j==0){

isAllZero = true;

}else{

matrixi0 = 0;

matrix0j = 0;

}

}

}

}

for(int i = 1;i<matrix.length;i++){

for(int j = 1;j<matrix0.length;j++){

if(matrixi0==0||matrix0j==0){

matrixij = 0;

}

}

}

for(int i = 0;i<matrix0.length;i++){

if(matrix00==0){

matrix0i =0;

}

}

if(isAllZero){

for(int i = 0;i<matrix.length;i++){

matrixi0 =0;

}

}

}

}

相关推荐
Tim_108 分钟前
【LeetCode】338、比特位计数
c++·算法·leetcode
木子算法23 分钟前
不是重心也不是中点:费马—韦伯点、它的最优性条件与迭代求解
人工智能·算法·目标跟踪
tryxr1 小时前
矩阵的几种基础变换
java·数据结构·算法·矩阵
mmmmath_31 小时前
LeetCode.028.找出字符串中第一个匹配项的
数据结构·算法·leetcode
Selvaggia2 小时前
DMD(Distribution Matching Distillation,分布匹配蒸馏)
算法
Navigator_Z2 小时前
LeetCode //C - 1255. Maximum Score Words Formed by Letters
c语言·算法·leetcode
All for pursuit.2 小时前
【栈-4】739.每日温度
数据结构·c++·算法·leetcode
All for pursuit.2 小时前
【栈-5】84.柱状图中最大的矩形
数据结构·c++·算法·leetcode
wzdark3 小时前
数据压缩算法的时间复杂度与压缩率权衡4
算法
小陈phd3 小时前
深入理解agent学习笔记(一)——现代agent介绍
人工智能·算法