当前位置:网站首页>LeetCode 2319. Judge whether the matrix is an X matrix
LeetCode 2319. Judge whether the matrix is an X matrix
2022-07-19 10:51:00 【Michael Amin】
List of articles
1. subject
If a square matrix satisfies the following All Conditions , It is called a X matrix :
- matrix Diagonals All elements on are No 0
- All in the matrix other The elements 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 .
Example 1:
Input :grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]
Output :true
explain : The matrix is shown in the figure above .
X The matrix should satisfy : Green elements ( On the diagonal ) Are not 0 , Red elements are 0 .
therefore ,grid It's a X matrix .
Example 2:
Input :grid = [[5,7,0],[0,3,1],[0,5,0]]
Output :false
explain : The matrix is shown in the figure above .
X The matrix should satisfy : Green elements ( On the diagonal ) Are not 0 , Red elements are 0 .
therefore ,grid Is not a X matrix .
Tips :
n == grid.length == grid[i].length
3 <= n <= 100
0 <= grid[i][j] <= 10^5
source : Power button (LeetCode)
link :https://leetcode.cn/problems/check-if-matrix-is-x-matrix
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
2. Problem solving
- simulation
class Solution:
def checkXMatrix(self, grid: List[List[int]]) -> bool:
for i in range(len(grid)):
for j in range(len(grid)):
if i==j or i+j==len(grid)-1:
if grid[i][j]==0:
return False
elif grid[i][j] != 0:
return False
return True
48 ms 15.6 MB Python3
my CSDN Blog address https://michael.blog.csdn.net/
Long click or sweep code pay attention to my official account (Michael amin ), Come on together 、 Learn together !
边栏推荐
- Autojs learning - multi function treasure chest - bottom
- Common collection properties
- ue4对动画蓝图的理解
- Design and Simulation of intelligent storage cabinet control system
- 多元线性回归详解
- 华为机试:连续出牌数量
- About hping streaming test tool
- 电商销售数据分析与预测(日期数据统计、按天统计、按月统计)
- 新增、修改操作時自定義複雜邏輯校驗-2022新項目
- Pytoch learning record 2 linear regression (tensor, variable)
猜你喜欢

Pytorch框架 学习记录1 CIFAR-10分类

JSP based novel writing and creation website

Use testeract JS offline recognition picture text record

如何在双链笔记软件中建立仪表盘和知识库?以嵌入式小组件库 NotionPet 为例

Data Lake solutions of various manufacturers

从预测到决策,九章云极DataCanvas推出YLearn因果学习开源项目

Opencv programming: opencv3 X trains its own classifier

分类任务中的类别不平衡问题

(一)了解MySQL

vulnhub inclusiveness: 1
随机推荐
Redis集群、一主二从三哨兵的搭建
SVN学习
军品研制过程所需文件-进阶版
Autojs learning - Dynamic decryption
[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
[acwing] 60th weekly match b- 4495 Array operation
C serialport configuration and attribute understanding
ue4对动画蓝图的理解
Common collection properties
How to use SVG to make text effects arranged along any path
mysql 查询报错
金鱼哥RHCA回忆录:CL210描述OPENSTACK控制平面--识别overclound控制平台服务+章节实验
SAP ABAP CDS view 视图的 Replacement 技术介绍
可定义的6G安全架构
开发第一个Flink应用
Integrated network architecture and network slicing technology of air, earth and sea
从预测到决策,九章云极DataCanvas推出YLearn因果学习开源项目
LeetCode 2249. Count the number of grid points in the circle
自动化之图形界面库pyautogui
Pytoch framework learning record 1 cifar-10 classification