Skip to content

Commit e49a9f8

Browse files
authored
feat: add typescript solution to lc problem: No.2133 (doocs#663)
No.2133.Check if Every Row and Column Contains All Numbers
1 parent 9f6af49 commit e49a9f8

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,20 @@
7171
<!-- 这里可写当前语言的特殊实现逻辑 -->
7272

7373
```ts
74-
74+
function checkValid(matrix: number[][]): boolean {
75+
const n = matrix.length;
76+
let rows = Array.from({ length: n }, () => new Array(n).fill(false));
77+
let cols = Array.from({ length: n }, () => new Array(n).fill(false));
78+
for (let i = 0; i < n; i++) {
79+
for (let j = 0; j < n; j++) {
80+
let cur = matrix[i][j];
81+
if (rows[i][cur] || cols[j][cur]) return false;
82+
rows[i][cur] = true;
83+
cols[j][cur] = true;
84+
}
85+
}
86+
return true;
87+
};
7588
```
7689

7790
### **...**

solution/2100-2199/2133.Check if Every Row and Column Contains All Numbers/README_EN.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,20 @@ Hence, we return false.
5656
### **TypeScript**
5757

5858
```ts
59-
59+
function checkValid(matrix: number[][]): boolean {
60+
const n = matrix.length;
61+
let rows = Array.from({ length: n }, () => new Array(n).fill(false));
62+
let cols = Array.from({ length: n }, () => new Array(n).fill(false));
63+
for (let i = 0; i < n; i++) {
64+
for (let j = 0; j < n; j++) {
65+
let cur = matrix[i][j];
66+
if (rows[i][cur] || cols[j][cur]) return false;
67+
rows[i][cur] = true;
68+
cols[j][cur] = true;
69+
}
70+
}
71+
return true;
72+
};
6073
```
6174

6275
### **...**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function checkValid(matrix: number[][]): boolean {
2+
const n = matrix.length;
3+
let rows = Array.from({ length: n }, () => new Array(n).fill(false));
4+
let cols = Array.from({ length: n }, () => new Array(n).fill(false));
5+
for (let i = 0; i < n; i++) {
6+
for (let j = 0; j < n; j++) {
7+
let cur = matrix[i][j];
8+
if (rows[i][cur] || cols[j][cur]) return false;
9+
rows[i][cur] = true;
10+
cols[j][cur] = true;
11+
}
12+
}
13+
return true;
14+
};

0 commit comments

Comments
 (0)