avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

2319Determine whether the matrix is ​​one X matrix One question daily

  2024-01-01        
字数统计: 141字   |   阅读时长: 1min

topic:

2023-01-31 (2).png
2319. Determine whether the matrix is ​​one X matrix

Thought:

GolangPure violence,PythonLearn Spirit God
The downward bidding on the main diagonal needs to be satisfied:i=j
Opposition to the corner line is satisfied:i+j=n−1

Code:

1
2
3
4
5
class Solution:
def checkXMatrix(self, grid: List[List[int]]) -> bool:
return all(
(v != 0) == (i == j or i + j == len(grid) - 1) for i, row in enumerate(grid) for j, v in enumerate(row))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
func checkXMatrix(grid [][]int) bool {
for i := 0; i < len(grid); i++ {
for j := 0; j < len(grid[i]); j++ {
//Two numbers in the first line
if (i == j) || (i+j == len(grid)-1) {
if grid[i][j] == 0 {
return false
}
} else if grid[i][j] != 0 {
return false
}
}
}
return true
}
  • Python
  • answer

扫一扫,分享到微信

微信分享二维码
2325Decrypt One question daily
2331Calculate the value of the Boolean binary tree One question daily
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号