73. Set Matrix Zeroes
Posted 鸵鸟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了73. Set Matrix Zeroes相关的知识,希望对你有一定的参考价值。
public class Solution { public void setZeroes(int[][] matrix) { if(matrix.length==0||matrix[0].length==0) return; boolean row0=false; for(int i=0;i<matrix.length;i++) for(int j=0;j<matrix[0].length;j++) if(matrix[i][j]==0) { if(i==0) row0=true; else { matrix[i][0]=0; matrix[0][j]=0; } } for(int i=matrix.length-1;i>=0;i--) for(int j=matrix[0].length-1;j>=0;j--) { if(i==0) matrix[i][j]=row0==true?0:matrix[i][j]; else if(matrix[0][j]==0||matrix[i][0]==0) matrix[i][j]=0; } } }
以上是关于73. Set Matrix Zeroes的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode OJ 73. Set Matrix Zeroes