dlehdanakf / Codingtest-Study

알고리즘 코딩테스트 토막지식 정리
1 stars 0 forks source link

PermMissingElem #8

Open dlehdanakf opened 3 years ago

dlehdanakf commented 3 years ago

개요

오답내용

0 1 2 3 4
1 2 4 5 6
function solution(A) {
    const N = new Array(A.length).fill(false);
    for(let i = 0; i < A.length; i++) {
        N[A[i] - 1] = true;
    }

    return N.indexOf(false) + 1;
}
function solution(A) {
    const N = new Array(A.length + 1).fill(false);
    for(let i = 0; i < A.length; i++) {
        N[A[i] - 1] = true;
    }

    return N.findIndex(e => e === false) + 1;
}