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

边栏推荐
- poj 3237 Tree(树链拆分)
- Bitbucket installation configuration
- 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
- [Yugong series] go teaching course in July 2022 004 go code Notes
- Daily question brushing record (XIV)
- Win11运行cmd提示“请求的操作需要提升”的解决方法
- C language knowledge points link
- 怎么利用Tensorflow2进行猫狗分类识别
- 阿龙的感悟
- How can Huawei online match improve the success rate of player matching
猜你喜欢

总结出现2xx、3xx、4xx、5xx状态码的原因

Reptile practice

Recovery technology with checkpoints

Dbeaver executes multiple insert into error processing at the same time

Scenario interview: ten questions and ten answers about distributed locks

华为联机对战如何提升玩家匹配成功几率

Type of fault

Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法

华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010

Sentinel production environment practice (I)
随机推荐
Daily question brushing record (XIV)
CRM creates its own custom report based on fetch
阿龙的感悟
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Shell script, awk condition judgment and logic comparison &||
Image editor for their AutoLayout environment
Oracle HugePages没有被使用导致服务器很卡的解决方法
Overview of database recovery
如何開發引入小程序插件
HDU 4391 paint the wall segment tree (water
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
EBS Oracle 11g 克隆步骤(单节点)
Win11运行cmd提示“请求的操作需要提升”的解决方法
Analyse des risques liés aux liaisons de microservices
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
Common interview questions of redis factory
Reptile practice
Three components of openpyxl
HYSBZ 2243 染色 (树链拆分)
每日刷题记录 (十四)