Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d92d3b4

Browse files
committed
feat: add solutions to lc problem: No.2319
No.2319.Check if Matrix Is X-Matrix
1 parent ddefa25 commit d92d3b4

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

‎solution/2300-2399/2319.Check if Matrix Is X-Matrix/README.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,47 @@ public class Solution {
182182
}
183183
```
184184

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+
185226
### **...**
186227
187228
```

‎solution/2300-2399/2319.Check if Matrix Is X-Matrix/README_EN.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,47 @@ public class Solution {
168168
}
169169
```
170170

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+
171212
### **...**
172213
173214
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /