본문 바로가기

항해99_10기/[2주차] 알고리즘 문제풀이

[34번][중상] 폰켓몬

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

나의 풀이

* 폰켓몬
 * 총 폰켓몬 수 / 2 = nums.length / 2
 * 총 폰켓몬 종류 = Math.max([...nums]) or new Set(nums).length or sort(a-b)[.length-1]
 * 가질 수 있는 최대 폰켓몬 수 = nums.length/2 or Math.max([...nums])

 

function solution(nums) {
  let pos = nums.length / 2;
  let types = new Set(nums).size;

  return pos >= types ? types : pos;
}

console.log(solution([3, 1, 2, 3]));
console.log(solution([3, 3, 3, 2, 2, 4]));
console.log(solution([3, 3, 3, 2, 2, 2]));

이 문제는 너무 간단해서.. 왜 중상인줄 모르겠는..??