// const comb = (arr, index) => {
// let result = [];
// if(index === 1) return arr.map((v)=>[v]);
// arr.forEach((v,index1,arr)=>{
// let fixed = v;
// let restArr = arr.slice(index1+1);
// let combArr = comb(restArr,index-1);
// let combination = combArr.map((v)=>[fixed,...v]);
// result.push(...combination);
// })
// return result;
// }
function solution(nums) {
var answer = 0;
let check = new Set(nums);
if(check.size === nums.length){
return nums.length/2;
}
else {
let half = nums.length/2;
let size = check.size;
if(size > half) {
return half;
}
else {
return size;
}
}
}
조합으로 작성하면 n이 200000까지 가는 상태에서는 당연히 시간 초과가 발생
그렇다면, 배열과 set의 차이를 통해서 해결하면 되지 않을까 생각