Skip to content

Commit d52ce98

Browse files
add 2784
1 parent 70b936f commit d52ce98

File tree

2 files changed

+28
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src/main/java/com/fishercoder/solutions/thirdthousand

2 files changed

+28
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2824.java) | | Easy |
1111
| 2812 | [Find the Safest Path in a Grid](https://leetcode.com/problems/find-the-safest-path-in-a-grid/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2812.java) | | Medium |BFS
1212
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2810.java) | | Easy |
13+
| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2784.java) | | Easy |
1314
| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2778.java) | | Easy |
1415
| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2769.java) | | Easy |
1516
| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2765.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2784 {
7+
public static class Solution1 {
8+
public boolean isGood(int[] nums) {
9+
int max = -1;
10+
for (int i = 0; i < nums.length; i++) {
11+
max = Math.max(max, nums[i]);
12+
}
13+
if (nums.length != max + 1) {
14+
return false;
15+
}
16+
Set<Integer> set = new HashSet<>();
17+
for (int num : nums) {
18+
if (!set.add(num)) {
19+
if (num != max) {
20+
return false;
21+
}
22+
}
23+
}
24+
return set.size() == max;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)