File tree Expand file tree Collapse file tree 4 files changed +113
-0
lines changed
solution/2300-2399/2319.Check if Matrix Is X-Matrix Expand file tree Collapse file tree 4 files changed +113
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,47 @@ public class Solution {
182
182
}
183
183
```
184
184
185
+ ### ** Rust**
186
+
187
+ ``` rust
188
+ impl Solution {
189
+ pub fn check_x_matrix (grid : Vec <Vec <i32 >>) -> bool {
190
+ let n = grid . len ();
191
+ for i in 0 .. n {
192
+ for j in 0 .. n {
193
+ if i == j || i + j == n - 1 {
194
+ if grid [i ][j ] == 0 {
195
+ return false ;
196
+ }
197
+ } else if grid [i ][j ] != 0 {
198
+ return false ;
199
+ }
200
+ }
201
+ }
202
+ true
203
+ }
204
+ }
205
+ ```
206
+
207
+ ### ** C**
208
+
209
+ ``` c
210
+ bool checkXMatrix (int ** grid, int gridSize, int * gridColSize) {
211
+ for (int i = 0; i < gridSize; i++) {
212
+ for (int j = 0; j < gridSize; j++) {
213
+ if (i == j || i + j == gridSize - 1) {
214
+ if (grid[ i] [ j ] == 0) {
215
+ return false;
216
+ }
217
+ } else if (grid[ i] [ j ] != 0) {
218
+ return false;
219
+ }
220
+ }
221
+ }
222
+ return true;
223
+ }
224
+ ```
225
+
185
226
### **...**
186
227
187
228
```
Original file line number Diff line number Diff line change @@ -168,6 +168,47 @@ public class Solution {
168
168
}
169
169
```
170
170
171
+ ### ** Rust**
172
+
173
+ ``` rust
174
+ impl Solution {
175
+ pub fn check_x_matrix (grid : Vec <Vec <i32 >>) -> bool {
176
+ let n = grid . len ();
177
+ for i in 0 .. n {
178
+ for j in 0 .. n {
179
+ if i == j || i + j == n - 1 {
180
+ if grid [i ][j ] == 0 {
181
+ return false ;
182
+ }
183
+ } else if grid [i ][j ] != 0 {
184
+ return false ;
185
+ }
186
+ }
187
+ }
188
+ true
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### ** C**
194
+
195
+ ``` c
196
+ bool checkXMatrix (int ** grid, int gridSize, int * gridColSize) {
197
+ for (int i = 0; i < gridSize; i++) {
198
+ for (int j = 0; j < gridSize; j++) {
199
+ if (i == j || i + j == gridSize - 1) {
200
+ if (grid[ i] [ j ] == 0) {
201
+ return false;
202
+ }
203
+ } else if (grid[ i] [ j ] != 0) {
204
+ return false;
205
+ }
206
+ }
207
+ }
208
+ return true;
209
+ }
210
+ ```
211
+
171
212
### **...**
172
213
173
214
```
Original file line number Diff line number Diff line change
1
+ bool checkXMatrix (int * * grid , int gridSize , int * gridColSize ) {
2
+ for (int i = 0 ; i < gridSize ; i ++ ) {
3
+ for (int j = 0 ; j < gridSize ; j ++ ) {
4
+ if (i == j || i + j == gridSize - 1 ) {
5
+ if (grid [i ][j ] == 0 ) {
6
+ return false;
7
+ }
8
+ } else if (grid [i ][j ] != 0 ) {
9
+ return false;
10
+ }
11
+ }
12
+ }
13
+ return true;
14
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn check_x_matrix ( grid : Vec < Vec < i32 > > ) -> bool {
3
+ let n = grid. len ( ) ;
4
+ for i in 0 ..n {
5
+ for j in 0 ..n {
6
+ if i == j || i + j == n - 1 {
7
+ if grid[ i] [ j] == 0 {
8
+ return false ;
9
+ }
10
+ } else if grid[ i] [ j] != 0 {
11
+ return false ;
12
+ }
13
+ }
14
+ }
15
+ true
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments