Skip to content

Commit

Permalink
add 2133
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed Jan 9, 2022
1 parent 4806a7d commit 92e72bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★

| # | Title | Solutions | Video | Difficulty | Tag
|-----|----------------|---------------|--------|-------------|-------------
|2133|[Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2133.java) ||Easy||
|2130|[Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2130.java) ||Medium||
|2129|[Capitalize the Title](https://leetcode.com/problems/capitalize-the-title/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2129.java) ||Easy||
|2126|[Destroying Asteroids](https://leetcode.com/problems/destroying-asteroids/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2126.java) ||Medium||
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/fishercoder/solutions/_2133.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fishercoder.solutions;

import java.util.HashSet;
import java.util.Set;

public class _2133 {
public static class Solution1 {
public boolean checkValid(int[][] matrix) {
int n = matrix.length;
Set<Integer> set = new HashSet<>();
for (int i = 1; i <= n; i++) {
set.add(i);
}
for (int i = 0; i < n; i++) {
Set<Integer> copy = new HashSet<>(set);
for (int j = 0; j < n; j++) {
if (!copy.remove(matrix[i][j])) {
return false;
}
}
}
for (int j = 0; j < n; j++) {
Set<Integer> copy = new HashSet<>(set);
for (int i = 0; i < n; i++) {
if (!copy.remove(matrix[i][j])) {
return false;
}
}
}
return true;
}
}
}

0 comments on commit 92e72bd

Please sign in to comment.