
심플하게 생각해서 푼 문제다. 간단하게 Set 객체 하나 써서 해결했다.
|
function solution(X, A) {
const set = new Set();
for (let index = 0; index < A.length; index += 1) {
set.add(A[index]);
if (set.size === X) {
return index;
}
}
return -1;
}
|
결과

'공부 > 알고리즘' 카테고리의 다른 글
| Codility - Lesson 4 : MissingInteger (0) | 2022.03.28 |
|---|---|
| Codility - Lesson 4 : MaxCounters (0) | 2022.03.24 |
| Codility - Lesson 3 : PermMissingElem (0) | 2022.03.22 |
| Codility - Lesson 2 : OddOcurrencesInArray (0) | 2022.03.20 |
| Codility - Lesson 1 : Iterations (0) | 2022.03.20 |