MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / setZeroes

Method setZeroes

Java/set-matrix-zeroes.java:2–33  ·  view source on GitHub ↗
(int[][] matrix)

Source from the content-addressed store, hash-verified

1class Solution {
2 public void setZeroes(int[][] matrix) {
3 Boolean isCol = false;
4 int R = matrix.length, C = matrix[0].length;
5 for (int i = 0; i < R; i++) {
6 if (matrix[i][0] == 0) {
7 isCol = true;
8 }
9 for (int j = 1; j < C; j++) {
10 if (matrix[i][j] == 0) {
11 matrix[0][j] = 0;
12 matrix[i][0] = 0;
13 }
14 }
15 }
16 for (int i = 1; i < R; i++) {
17 for (int j = 1; j < C; j++) {
18 if (matrix[i][0] == 0 || matrix[0][j] == 0) {
19 matrix[i][j] = 0;
20 }
21 }
22 }
23 if (matrix[0][0] == 0) {
24 for (int j = 0; j < C; j++) {
25 matrix[0][j] = 0;
26 }
27 }
28 if (isCol) {
29 for (int i = 0; i < R; i++) {
30 matrix[i][0] = 0;
31 }
32 }
33 }
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected