Skip to content

Commit 3c9e0c2

Browse files
committedAug 19, 2021
Upgrade problem 73
1 parent dec8239 commit 3c9e0c2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎src/main/java/io/github/juchanei/leetcodeJava/SetMatrixZeroes.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ public void setZeroes(int[][] matrix) {
1313
}
1414

1515
private void setZeroes(int x, int y, boolean isZero) {
16-
if (x + 1 < matrix[y].length) setZeroes(x + 1, y, matrix[y][x + 1] == 0);
17-
else if (y + 1 < matrix.length) setZeroes(0, y + 1, matrix[y + 1][0] == 0);
16+
boolean found = false;
17+
for (int i = y; i < matrix.length && !found; i++) {
18+
for (int j = i == y ? x + 1 : 0; j < matrix[i].length && !found; j++) {
19+
if (matrix[i][j] == 0) {
20+
setZeroes(j, i, true);
21+
22+
found = true;
23+
}
24+
}
25+
}
1826

1927
if (!isZero) return;
2028

0 commit comments

Comments
 (0)
Please sign in to comment.