-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCondoDevelopers.java
51 lines (45 loc) · 1.4 KB
/
CondoDevelopers.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*https://binarysearch.com/problems/Condo-Developers*/
import java.util.*;
class Solution {
public int[][] solve(int[][] matrix) {
int m = matrix.length, n = matrix[0].length, i, j;
int[] maxRow = new int[m], maxCol = new int[n];
int max = 0;
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
if (matrix[i][j] > maxRow[i])
maxRow[i] = matrix[i][j];
}
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
if (matrix[i][j] > maxCol[j])
maxCol[j] = matrix[i][j];
}
for (i = 0; i < m; ++i)
for (j = 0; j < n; ++j)
matrix[i][j] = Math.min(maxRow[i],maxCol[j]);
return matrix;
}
}
import java.util.*;
class Solution {
public int[][] solve(int[][] matrix) {
int m = matrix.length, n = matrix[0].length, i, j;
int[] maxRow = new int[m], maxCol = new int[n];
int max = 0;
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
if (matrix[i][j] > maxRow[i]) maxRow[i] = matrix[i][j];
if (matrix[i][j] > maxCol[j]) maxCol[j] = matrix[i][j];
}
}
for (i = 0; i < m; ++i)
for (j = 0; j < n; ++j)
matrix[i][j] = Math.min(maxRow[i],maxCol[j]);
return matrix;
}
}