기록하는 공간

[코딜리티] PermMissingElem 본문

알고리즘/Codility

[코딜리티] PermMissingElem

llollhh_ 2019. 1. 16. 01:23
문제
  • N의 길이를 가지는 A라는 배열이 있다. A라는 배열에는 1 부터 (N + 1) 까지 수 중에 중복되지 않게 랜덤으로 들어가 있다.

  • N의 범위는 1~100,000 입니다.

function solution(A) { const arrayLength = A.length; let i = 1; if (arrayLength < 1){ return 1; } if (!A.includes(arrayLength + 1)){ return arrayLength + 1; } A = A.sort((f, s) => { return f-s; }); while (i <= arrayLength){ if (i !== A[i-1]){ return i; } i++; } }


'알고리즘 > Codility' 카테고리의 다른 글

[코딜리티] Flog Jumb  (0) 2019.01.12
[코딜리티] CyclicRotation  (0) 2019.01.09
[코딜리티] BinaryGap(이진 갭 알고리즘)  (0) 2018.12.15
[코딜리티] OddOccurrencesInArray  (0) 2018.10.24
Comments