Skip to content

Commit 01b8059

Browse files
authored
Create 5976-check-if-every-row-and-column-contains-all-numbers.js
1 parent cae1481 commit 01b8059

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {boolean}
4+
*/
5+
var checkValid = function(matrix) {
6+
const n = matrix.length
7+
let res = true
8+
for(let i = 0; i < n; i++) {
9+
if(!chkRow(i) || !chkCol(i)) {
10+
res = false
11+
break
12+
}
13+
}
14+
15+
16+
return res
17+
18+
function chkRow(i) {
19+
const row = matrix[i], set = new Set()
20+
for(let i = 0; i < n; i++) {
21+
set.add(row[i])
22+
}
23+
return set.size === n
24+
}
25+
26+
function chkCol(j) {
27+
const set = new Set()
28+
for(let i = 0; i < n; i++) {
29+
set.add(matrix[i][j])
30+
}
31+
32+
return set.size === n
33+
}
34+
};

0 commit comments

Comments
 (0)