当前位置:网站首页>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

边栏推荐
- 极狐公司官方澄清声明
- HYSBZ 2243 染色 (树链拆分)
- Two stage locking protocol for concurrency control
- Create a virtual machine on VMware (system not installed)
- 华为联机对战如何提升玩家匹配成功几率
- Form artifact
- Performance monitoring of database tuning solutions
- How to develop and introduce applet plug-ins
- EBS Oracle 11g 克隆步骤(单节点)
- A long's perception
猜你喜欢

Dbeaver executes multiple insert into error processing at the same time

Analysis and test of ModbusRTU communication protocol

科技云报道:算力网络,还需跨越几道坎?

AD637 usage notes

Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~

装饰器学习01

Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned

MMAP

Decorator learning 01

Huawei cloud modelarts text classification - takeout comments
随机推荐
"Chris Richardson microservices series" uses API gateway to build microservices
科技云报道:算力网络,还需跨越几道坎?
database mirroring
Livelocks and deadlocks of concurrency control
Poj3414广泛搜索
Net small and medium-sized enterprise project development framework series (one)
Talking about MySQL index
DBeaver同时执行多条insert into报错处理
Advantages of robot framework
Analyse des risques liés aux liaisons de microservices
QML reported an error expected token ";", expected a qualified name ID
让开发效率提升的跨端方案
每日刷题记录 (十四)
深信服X计划-网络协议基础 DNS
Oracle检查点队列–实例崩溃恢复原理剖析
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
AD637使用筆記
Poj 3237 Tree (Tree Chain Split)
Poj3414 extensive search