Skip to content

Commit 0f3b334

Browse files
Create 2482-difference-between-ones-and-zeros-in-row-and-column.java
1 parent 0a6e6a6 commit 0f3b334

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int[][] onesMinusZeros(int[][] grid) {
3+
int r = grid.length, c = grid[0].length;
4+
int[] onesRow = new int[r];
5+
int[] onesCol = new int[c];
6+
7+
for(int i = 0; i < r; i++){
8+
for(int j = 0; j < c; j++){
9+
onesRow[i] += grid[i][j];
10+
onesCol[j] += grid[i][j];
11+
}
12+
}
13+
14+
int[][] res = new int[r][c];
15+
for(int i = 0; i < r; i++){
16+
for(int j = 0; j < c; j++){
17+
int no = 2 * onesRow[i] + 2 * onesCol[j] - r - c;
18+
res[i][j] = no;
19+
}
20+
}
21+
return res;
22+
}
23+
}

0 commit comments

Comments
 (0)