function solution(A) {
let numbers = {};
let n = A.length;
let sumAll = 0;
let sumN = n * (n + 1) / 2; // sum(1~N):

for (let i = 0; i < n; i++) {
if (numbers[A[i]]) {
return 0; // duplicated
} else {
numbers[A[i]] = true;
}
sumAll += A[i];
}

return sumAll === sumN ? 1 : 0;
}


'IT General' 카테고리의 다른 글

Codility #11-MaxCounters  (0) 2018.09.18
Codility #10-FrogRiverOne  (0) 2018.09.18
Codility #8-TapeEquilibrium  (0) 2018.09.18
Codility #7-Brackets  (0) 2018.08.18
Codility #7-Nesting  (0) 2018.08.18

+ Recent posts