Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b9aa0ac

Browse files
Add 폰켓몬.js
1 parent 214fc3a commit b9aa0ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎level-1/폰켓몬.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ function solution(nums) {
4444

4545
return unique.length > nums.length / 2 ? nums.length / 2 : unique.length;
4646
}
47+
48+
//정답 5 - chaerin-dev
49+
function solution(nums) {
50+
// 가질 수 있는 폰켓몬의 수
51+
const getCnt = nums.length / 2;
52+
// 폰켓몬 종류의 수
53+
const setSize = new Set(nums).size;
54+
// 내가 가질 수 있는 폰켓몬의 수보다 폰켓몬 종류의 수가 더 많으면
55+
// -> 모두 다른 종류의 폰켓몬을 하나씩 가질 수 있음
56+
// 내가 가질 수 있는 폰켓몬의 수보다 폰켓몬 종류의 수가 더 적으면
57+
// -> 최대한 다양한 종류의 폰켓몬을 가지려고 해도 원래 있던 폰켓몬 종류의 수가 최대로 가질 수 있는 폰켓몬 종류의 수
58+
return setSize > getCnt ? getCnt : setSize;
59+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /