Skip to content

Commit 03349e8

Browse files
authored
Create Check if an Array Is Consecutive.java
1 parent ae399d8 commit 03349e8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public boolean isConsecutive(int[] nums) {
3+
int min = Integer.MAX_VALUE;
4+
for (int num : nums) {
5+
min = Math.min(num, min);
6+
}
7+
Set<Integer> set = new HashSet<>();
8+
for (int num : nums) {
9+
if (num - min >= nums.length || !set.add(num - min)) {
10+
return false;
11+
}
12+
}
13+
return true;
14+
}
15+
}

0 commit comments

Comments
 (0)