[Algorithm] 26 week(7.11 ~ 7.17) 3/3

Dev_min·2022년 7월 13일
0

algorithm

목록 보기
83/157

프로그래머스 포켓몬

function solution(nums) {
    const pick = nums.length / 2;
    const hash = new Set();
    
    for(let i = 0; i < nums.length; i++){
        hash.add(nums[i]);
    };
    
    if(hash.size < pick){
        return hash.size;
    }
    
    return pick;
}

다른사람 풀이

function solution(nums) {
  const max = nums.length / 2;
  const arr = [...new Set(nums)];

  return arr.length > max ? max : arr.length
}
profile
TIL record

0개의 댓글