当前位置:网站首页>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
边栏推荐
- 他们主动布局(autolayout)环境的图像编辑器
- PIP install beatifulsoup4 installation failed
- EBS Oracle 11g cloning steps (single node)
- Huawei fast game failed to call the login interface, and returned error code -1
- 华为快游戏调用登录接口失败,返回错误码 -1
- 总结出现2xx、3xx、4xx、5xx状态码的原因
- Microservice link risk analysis
- 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
- Concurrency control of performance tuning methodology
- Common interview questions of JVM manufacturers
猜你喜欢
Index optimization of performance tuning methodology
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
Two stage locking protocol for concurrency control
Storage optimization of performance tuning methodology
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Summary of concurrency control
Business learning of mall order module
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
AD637使用笔记
AD637使用筆記
随机推荐
Scenario interview: ten questions and ten answers about distributed locks
Shell script, awk uses if, for process control
AD637使用笔记
Daily question brushing record (XIV)
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
"Chris Richardson microservices series" uses API gateway to build microservices
元宇宙中的三大“派系”
Defect detection - Halcon surface scratch detection
Image editor for their AutoLayout environment
Analysis and test of ModbusRTU communication protocol
Detailed explanation of memset() function usage
MMAP
Implementation technology of recovery
Kingbasees v8r3 data security case - audit record clearing case
如何组织一场实战攻防演练
Huawei fast game failed to call the login interface, and returned error code -1
Pointer parameter passing vs reference parameter passing vs value parameter passing
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
Storage optimization of performance tuning methodology
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017