We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f4d6be commit 7465357Copy full SHA for 7465357
2784.Check-if-Array-is-Good.java
@@ -0,0 +1,34 @@
1
+// https://leetcode.com/problems/check-if-array-is-good/
2
+// algorithms
3
+// Easy (48.73%)
4
+// Total Accepted: 21.1K
5
+// Total Submissions: 43.3K
6
+
7
8
+class Solution {
9
10
+ public boolean isGood(int[] nums) {
11
+ int len = nums.length;
12
13
+ int[] flag = new int[len + 1];
14
+ for (int n : nums) {
15
+ if (n >= len) {
16
+ return false;
17
+ }
18
19
+ flag[n] += 1;
20
+ if (flag[n] > 1 && n != len - 1) {
21
22
23
24
25
+ for (int i = 1; i < len; i++) {
26
+ if (flag[i] == 0) {
27
28
29
30
31
+ return flag[len - 1] == 2;
32
33
34
+}
0 commit comments