Binary Journey

[프로그래머스] 폰켓몬 본문

프로그래머스/level 1

[프로그래머스] 폰켓몬

binaryJournalist 2021. 10. 18. 02:26
반응형

 

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

 

 

 

** Javascript

 

function solution(nums) {
    const result = [ ...new Set(nums)];
    return result.length < nums.length / 2 ? result.length : nums.length / 2;
}

 

 

 

이렇게 해도 된다

 

function solution(nums) {
    const result = [ ...new Set(nums)];
    return Math.min(result.length, nums.length / 2);
}

 

 

 

 

반응형