Skip to content

Commit 7ad5ce1

Browse files
author
Goutham Pradhan
committed
Accepted
1 parent 93d19bb commit 7ad5ce1

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

problems/src/SetMatrixZeroes.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.util.HashSet;
2+
import java.util.Set;
3+
4+
/**
5+
* Created by pradhang on 3/28/2017.
6+
* Accepted
7+
*/
8+
public class SetMatrixZeroes
9+
{
10+
/**
11+
* Main method
12+
* @param args
13+
* @throws Exception
14+
*/
15+
public static void main(String[] args) throws Exception
16+
{
17+
int[][] matrix = {{0, 8, 7}, {9, 0, 8}, {9, 9, 0}};
18+
19+
new SetMatrixZeroes().setZeroes(matrix);
20+
}
21+
22+
public void setZeroes(int[][] matrix)
23+
{
24+
Set<Integer> row = new HashSet<>();
25+
Set<Integer> col = new HashSet<>();
26+
int m = matrix.length;
27+
int n = matrix[0].length;
28+
for(int i = 0; i < m; i ++)
29+
{
30+
for(int j = 0; j < n; j ++)
31+
{
32+
if(matrix[i][j] == 0)
33+
{
34+
row.add(i);
35+
col.add(j);
36+
}
37+
}
38+
}
39+
40+
for(int r : row)
41+
{
42+
for(int j = 0; j < n; j++)
43+
{
44+
matrix[r][j] = 0;
45+
}
46+
}
47+
48+
for(int c : col)
49+
{
50+
for(int i = 0; i < m; i++)
51+
{
52+
matrix[i][c] = 0;
53+
}
54+
}
55+
}
56+
}

problems/src/ThirdMaximumNumber.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse;
2-
31
/**
42
* Created by gouthamvidyapradhan on 25/03/2017.
53
* Accepted

0 commit comments

Comments
 (0)