Skip to content

Commit 55482a7

Browse files
committed
Add solution #2133
1 parent fbd680b commit 55482a7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,767 LeetCode solutions in JavaScript
1+
# 1,768 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1634,6 +1634,7 @@
16341634
2130|[Maximum Twin Sum of a Linked List](./solutions/2130-maximum-twin-sum-of-a-linked-list.js)|Medium|
16351635
2131|[Longest Palindrome by Concatenating Two Letter Words](./solutions/2131-longest-palindrome-by-concatenating-two-letter-words.js)|Medium|
16361636
2132|[Stamping the Grid](./solutions/2132-stamping-the-grid.js)|Hard|
1637+
2133|[Check if Every Row and Column Contains All Numbers](./solutions/2133-check-if-every-row-and-column-contains-all-numbers.js)|Easy|
16371638
2140|[Solving Questions With Brainpower](./solutions/2140-solving-questions-with-brainpower.js)|Medium|
16381639
2145|[Count the Hidden Sequences](./solutions/2145-count-the-hidden-sequences.js)|Medium|
16391640
2154|[Keep Multiplying Found Values by Two](./solutions/2154-keep-multiplying-found-values-by-two.js)|Easy|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 2133. Check if Every Row and Column Contains All Numbers
3+
* https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/
4+
* Difficulty: Easy
5+
*
6+
* An n x n matrix is valid if every row and every column contains all the integers from 1
7+
* to n (inclusive).
8+
*
9+
* Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise,
10+
* return false.
11+
*/
12+
13+
/**
14+
* @param {number[][]} matrix
15+
* @return {boolean}
16+
*/
17+
var checkValid = function(matrix) {
18+
const n = matrix.length;
19+
20+
for (let i = 0; i < n; i++) {
21+
const rowSet = new Set();
22+
const colSet = new Set();
23+
24+
for (let j = 0; j < n; j++) {
25+
rowSet.add(matrix[i][j]);
26+
colSet.add(matrix[j][i]);
27+
}
28+
29+
if (rowSet.size !== n || colSet.size !== n) return false;
30+
}
31+
32+
return true;
33+
};

0 commit comments

Comments
 (0)