当前位置:网站首页>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
边栏推荐
- Analysis and test of ModbusRTU communication protocol
- database mirroring
- C language knowledge points link
- 华为快游戏调用登录接口失败,返回错误码 -1
- Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
- How can Huawei online match improve the success rate of player matching
- EL与JSTL注意事项汇总
- Livelocks and deadlocks of concurrency control
- Common interview questions of redis factory
- 华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
猜你喜欢
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
Index optimization of performance tuning methodology
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
ICMP 介绍
Reptile practice
华为联机对战如何提升玩家匹配成功几率
Concurrency control of performance tuning methodology
EBS Oracle 11g cloning steps (single node)
随机推荐
854. String BFS with similarity K
crm创建基于fetch自己的自定义报告
Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
"Chris Richardson microservices series" uses API gateway to build microservices
Tips for using SecureCRT
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Shell script, awk condition judgment and logic comparison &||
华为联机对战如何提升玩家匹配成功几率
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
Create a virtual machine on VMware (system not installed)
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
Concurrency control of performance tuning methodology
Three components of openpyxl
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
Form artifact
How to develop and introduce applet plug-ins
Comment développer un plug - in d'applet
How can Huawei online match improve the success rate of player matching