leetcode set matrix 0
原题:Given a m x n matrix, if an element is 0, set its entire row and column to 0.
public class Solution {
public void setZeroes(int[][] matrix) {
int rowLen=matrix.length;
int columnLen=matrix[0].length;
for(int i=0;i<rowLen;i++)
for(int j=0;j<columnLen;j++) {
if(matrix[i][j]==0) {
for(int k=0;k<rowLen;k++) {
matrix[k][j]=0;
}
for(int k=0;k<columnLen;k++) {
matrix[i][k]=0;
}
}
}
}
}
Input: [[0,0,0,5],[4,3,1,4],[0,1,1,4],[1,2,1,3],[0,0,1,1]]
Output: [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
Expected: [[0,0,0,0],[0,0,0,4],[0,0,0,0],[0,0,0,3],[0,0,0,0]]
求问各位大神哪里有错哦。。。
楼主新手一枚- -