当前位置:网站首页>力扣 2319. 判断矩阵是否是一个 X 矩阵
力扣 2319. 判断矩阵是否是一个 X 矩阵
2022-07-07 17:53:00 【Tomorrowave】
2319. 判断矩阵是否是一个 X 矩阵
如果一个正方形矩阵满足下述 全部 条件,则称之为一个 X 矩阵 :
矩阵对角线上的所有元素都 不是 0
矩阵中所有其他元素都是 0
给你一个大小为 n x n 的二维整数数组 grid ,表示一个正方形矩阵。如果 grid 是一个 X 矩阵 ,返回 true ;否则,返回 false 。

涉及知识点:
二维矩阵的for循环
代码部分
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
边栏推荐
猜你喜欢

Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog

项目经理『面试八问』,看了等于会了

vulnhub之school 1

Leetcode force buckle (Sword finger offer 36-39) 36 Binary search tree and bidirectional linked list 37 Serialize binary tree 38 Arrangement of strings 39 Numbers that appear more than half of the tim

LeetCode_ 7_ five

vulnhub之tre1

el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。

vulnhub之Funfox2

【STL】vector

J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
随机推荐
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
How to cooperate among multiple threads
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
[RT thread env tool installation]
MySQL、sqlserver oracle数据库连接方式
Kirin Xin'an cloud platform is newly upgraded!
[sword finger offer] sword finger offer II 012 The sum of left and right subarrays is equal
ASP.NET体育馆综合会员管理系统源码,免费分享
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
ant desgin 多选
PMP practice once a day | don't get lost in the exam -7.7
Compiler optimization (4): inductive variables
Openeuler prize catching activities, to participate in?
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
Mysql, sqlserver Oracle database connection mode
JVM GC垃圾回收简述