Skip to content

Commit 9956b70

Browse files
committed
feat: Day04
1 parent 93cb128 commit 9956b70

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int smallestAbsent(int[] nums) {
3+
int sum = 0;
4+
Set<Integer> set = new HashSet<>();
5+
for (int num : nums) {
6+
sum += num;
7+
set.add(num);
8+
}
9+
10+
double average = (double) sum / nums.length;
11+
12+
int candidate = (int) Math.floor(average) + 1;
13+
if (candidate <= 0) candidate = 1; // must be positive
14+
15+
while (set.contains(candidate)) {
16+
candidate++;
17+
}
18+
19+
return candidate;
20+
}
21+
}

0 commit comments

Comments
 (0)