欢迎光临散文网 会员登陆 & 注册

LeetCode 2133. Check if Every Row and Column Contains All Number

2023-02-01 15:41 作者:您是打尖儿还是住店呢  | 我要投稿

An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).

Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.

 

Example 1:

Input: matrix = [[1,2,3],[3,1,2],[2,3,1]]Output: trueExplanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3. Hence, we return true.

Example 2:

Input: matrix = [[1,1,1],[1,2,3],[1,2,3]]Output: falseExplanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3. Hence, we return false.

 

Constraints:

  • n == matrix.length == matrix[i].length

  • 1 <= n <= 100

  • 1 <= matrix[i][j] <= n

Accepted

48,367

Submissions

91,720

Easy 题目,有点不值一提了。loop2个方向,如果有问题就false,没问题就返回true;


Runtime: 18 ms, faster than 83.24% of Java online submissions for Check if Every Row and Column Contains All Numbers.

Memory Usage: 43.3 MB, less than 78.96% of Java online submissions for Check if Every Row and Column Contains All Numbers.


LeetCode 2133. Check if Every Row and Column Contains All Number的评论 (共 条)

分享到微博请遵守国家法律