forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2319.java
32 lines (31 loc) · 969 Bytes
/
_2319.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
package com.fishercoder.solutions;
public class _2319 {
public static class Solution1 {
public boolean checkXMatrix(int[][] grid) {
int m = grid.length;
boolean[][] checked = new boolean[m][m];
for (int i = 0; i < m; i++) {
if (grid[i][i] == 0) {
return false;
} else {
checked[i][i] = true;
}
}
for (int i = 0, j = m - 1; i < m && j >= 0; i++, j--) {
if (grid[i][j] == 0) {
return false;
} else {
checked[i][j] = true;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (!checked[i][j] && grid[i][j] != 0) {
return false;
}
}
}
return true;
}
}
}