Clean Java code


  • 0
    C

    class Solution {
    public void setZeroes(int[][] matrix) {
    ArrayList<Integer> pos = new ArrayList<Integer>();
    int posz=pos.size();
    for(int i = 0;i<matrix.length;i++){
    for(int j =0;j<matrix[i].length;j++)
    {
    if(matrix[i][j]==0) {
    pos.add(j);
    }
    if ((j==matrix[i].length-1)&&posz<pos.size())
    {
    Arrays.fill(matrix[i],0);
    posz=pos.size();
    }
    }
    }
    Set<Integer> hs = new HashSet<>();
    hs.addAll(pos);
    pos.clear();
    pos.addAll(hs);
    System.out.println("\n\n\n");
    for(int j = 0;j<pos.size();j++){
    for(int i=0;i<matrix.length;i++){
    matrix[i][pos.get(j)]=0;
    }
    }
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.