2133. Check if Every Row and Column Contains All Numbers
Previous2134. Minimum Swaps to Group All 1's Together IINext632. Smallest Range Covering Elements from K Lists (H)
Last updated
Last updated
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:
Example 2:
Constraints:
n == matrix.length == matrix[i].length
1 <= n <= 100
1 <= matrix[i][j] <= n
Version 1: o(n*n)
'matrix' must consist of values from 1 to 3 only
所以我们可以用SET去重在做
Time: O(n^2)O(n2)
Space: O(n)O(n)
如果没有testcase限制, 'matrix' must consist of values from 1 to 3 only ,可以加上min, max控制:
Version 2: 空间换时间