Advertisement
DakshJain

Set Matrix Zeroes

Aug 26th, 2023
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class Solution {
  2. public void setZeroes(int[][] matrix) {
  3. int n=matrix.length;
  4. int m=matrix[0].length;
  5.  
  6. int row[]=new int[n];
  7. int column[]=new int[m];
  8. for(int i=0;i<n;i++){
  9. for(int j=0;j<m;j++){
  10.  
  11. if(matrix[i][j]==0){
  12. row[i]=1;
  13. column[j]=1;
  14. }
  15. }
  16. }
  17. for(int i=0;i<n;i++){
  18. for(int j=0;j<m;j++){
  19. if(row[i]==1 || column[j]==1) matrix[i][j]=0;
  20.  
  21. }
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement