当前位置:网站首页>Leetcode simple question: check whether each row and column contain all integers
Leetcode simple question: check whether each row and column contain all integers
2022-07-05 22:02:00 【·Starry Sea】
subject
For a size of n x n In terms of the matrix of , If each row and column contains from 1 To n Of All Integers ( contain 1 and n), The matrix is considered to be a It works matrix .
Give you a size of n x n The integer matrix of matrix , Please judge whether the matrix is an effective matrix : If it is , return true ; otherwise , return false .
Example 1:
Input :matrix = [[1,2,3],[3,1,2],[2,3,1]]
Output :true
explain : In this case ,n = 3 , Each row and column contains numbers 1、2、3 .
therefore , return true .
Example 2:
Input :matrix = [[1,1,1],[1,2,3],[1,2,3]]
Output :false
explain : In this case ,n = 3 , But the first row and first column do not contain numbers 2 and 3 .
therefore , return false .
Tips :
n == matrix.length == matrix[i].length
1 <= n <= 100
1 <= matrix[i][j] <= n
source : Power button (LeetCode)
Their thinking
Just check whether there are repeated numbers in each row of the matrix , Whether there is a duplicate number in each column .
class Solution:
def checkValid(self, matrix: List[List[int]]) -> bool:
for i in matrix: # Check each line
if len(set(i))!=len(matrix):
return False
temp=set()
for i in range(len(matrix)): # Check each column
temp.clear()
for j in range(len(matrix)):
temp.add(matrix[j][i])
if len(temp)!=len(matrix):
return False
return True
边栏推荐
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
- Oracle检查点队列–实例崩溃恢复原理剖析
- Blocking protocol for concurrency control
- 854. 相似度为 K 的字符串 BFS
- Shell script, awk condition judgment and logic comparison &||
- 微服务链路风险分析
- How to add new fields to mongodb with code (all)
- 微服務鏈路風險分析
- Two stage locking protocol for concurrency control
- Oracle checkpoint queue - Analysis of the principle of instance crash recovery
猜你喜欢
Official clarification statement of Jihu company
Database recovery strategy
[Yugong series] go teaching course in July 2022 004 go code Notes
AD637使用筆記
华为云ModelArts文本分类–外卖评论
Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
Serializability of concurrent scheduling
Shell script, awk condition judgment and logic comparison &||
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
随机推荐
HDU 4391 paint the wall segment tree (water
Performance monitoring of database tuning solutions
How to organize an actual attack and defense drill
How can Huawei online match improve the success rate of player matching
Net small and medium-sized enterprise project development framework series (one)
笔记本电脑蓝牙怎么用来连接耳机
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Codeforces 12D Ball 树形阵列模拟3排序元素
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
Oracle检查点队列–实例崩溃恢复原理剖析
Meituan dynamic thread pool practice ideas, open source
华为云ModelArts文本分类–外卖评论
EBS Oracle 11g cloning steps (single node)
Advantages of robot framework
如何开发引入小程序插件
Poj3414 extensive search