1. JavaScript
정해
function solution(A) {
A.sort((a, b) => a - b);
let min = 1;
for (let i in A) {
if (A[i] > 0 && A[i] == min) {
min++;
}
}
return min;
}
33%
function solution(A) {
let list = new Set(A);
list = [...list];
list.sort((a, b) => a - b);
if (list.slice(-1) < 0) {
return 1
} else {
for (i = 0; i < list.length; i++) {
if (list[i] + 1 != list[i + 1]) {
return list[i] + 1
}
}
}
}
2. Python
def solution(A):
A.sort()
min = 1
for i in range(len(A)):
if A[i] > 0 and A[i] == min:
min += 1
return min