유형 : 정렬
풀이 : Set 객체는 중복된 값을 허용하지 않는다는 것을 이용하여 풀 수 있다.
function solution(A) {
const array = A.slice();
let newSet = new Set();
for (let item of array) {
newSet.add(item);
}
return newSet.size;
}
console.log(solution([2, 1, 1, 2, 3, 1]));
'Programming > 데일리 알고리즘' 카테고리의 다른 글
[HackerRank] Largest Rectangle (Javascript) (0) | 2021.05.25 |
---|---|
(210519:BTB) Lesson 6. MaxProductOfThree (0) | 2021.05.19 |
[HackerRank] Balanced Brackets (Javascript) (0) | 2021.05.18 |
[HackerRank] Sherlock and the Valid String (Javascript) (0) | 2021.05.15 |
(210502:BTB) Lesson 5. CountDiv (0) | 2021.05.02 |