Skip to content

Commit dab0bcc

Browse files
authored
Create Check if Matrix Is X-Matrix.java
1 parent fd70090 commit dab0bcc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Easy/Check if Matrix Is X-Matrix.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public boolean checkXMatrix(int[][] grid) {
3+
int n = grid.length;
4+
for (int i = 0; i < n; i++) {
5+
for (int j = 0; j < n; j++) {
6+
if (i == j || i + j == n - 1) {
7+
if (grid[i][j] == 0) {
8+
return false;
9+
}
10+
} else {
11+
if (grid[i][j] != 0) {
12+
return false;
13+
}
14+
}
15+
}
16+
}
17+
return true;
18+
}
19+
}

0 commit comments

Comments
 (0)