当前位置:网站首页>Force buckle 2319 Judge whether the matrix is an X matrix
Force buckle 2319 Judge whether the matrix is an X matrix
2022-07-07 20:06:00 【Tomorrowave】
2319. Judge whether the matrix is a X matrix
If a square matrix satisfies the following All Conditions , It is called a X matrix :
All the elements on the diagonal of the matrix are No 0
All other elements in the matrix are 0
Give you a size of n x n A two-dimensional array of integers grid , Represents a square matrix . If grid It's a X matrix , return true ; otherwise , return false .

Knowledge points involved :
Two dimensional matrix for loop
Code section
class Solution:
def checkXMatrix(self, grid: List[List[int]]) -> bool:
for i in range(len(grid[0])):
for j in range(len(grid)):
if i==j or len(grid)-j-1==i :
if grid[i][j]==0:
return False
else:
if (grid[i][j]!=0):
return False
return True
边栏推荐
猜你喜欢

9 atomic operation class 18 Rohan enhancement

多个线程之间如何协同

LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字

Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.

PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!

ASP. Net learning & ASP's one word

剑指 Offer II 013. 二维子矩阵的和

Compiler optimization (4): inductive variables

8 CAS
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
随机推荐
时间工具类
使用高斯Redis实现二级索引
力扣 2319. 判断矩阵是否是一个 X 矩阵
实训九 网络服务的基本配置
Detailed explanation of Flink parallelism and slot
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
力扣674. 最长连续递增序列
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
编译器优化那些事儿(4):归纳变量
RESTAPI 版本控制策略【eolink 翻译】
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
力扣 459. 重复的子字符串
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
毕业季|遗憾而又幸运的毕业季
mysql 的一些重要知识
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
关于自身的一些安排
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图