-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetzero.java
More file actions
36 lines (31 loc) · 895 Bytes
/
Copy pathsetzero.java
File metadata and controls
36 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public void setZeroes(int[][] matrix) {
ArrayList <Integer> rowposition=new ArrayList<>();
ArrayList <Integer> columnpostition=new ArrayList<>();
for(int row=0;row<matrix.length;row++)
{
for(int column=0;column<matrix[0].length;column++)
{
if(matrix[row][column]==0)
{
rowposition.add(row);
columnpostition.add(column);
}
}
}
for(int elements : rowposition)
{
for(int i=0;i<matrix[0].length;i++)
{
matrix[elements][i]=0;
}
}
for(int elements: columnpostition)
{
for(int i=0;i<matrix.length;i++)
{
matrix[i][elements]=0;
}
}
}
}