Skip to content

Commit 3cabe48

Browse files
committed
solve : programmers 위장
1 parent 24ae46a commit 3cabe48

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/do02reen24/Review/week15.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# :fire: week15
2+
3+
## :ballot_box_with_check: 프로그래머스 위장(42578)
4+
5+
- 조합의 개념을 사용하여 풀 수 있었다.
6+
- 해당 옷을 아예 고르지 않는 경우도 있으므로 각 아이템 길이에 + 1 을 해주었다.
7+
- 모든 옷을 안고르는 경우는 제외해야하므로 정답에서 - 1 을 해주었다.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const getCombinationNumber = (object) => {
2+
let combination = 1;
3+
for (const key in object) {
4+
const itemLength = object[key].length + 1;
5+
combination *= itemLength;
6+
}
7+
return combination;
8+
};
9+
10+
const solution = (clothes) => {
11+
const closet = {};
12+
clothes.forEach(([cloth, clothType]) => {
13+
closet[clothType]
14+
? closet[clothType].push(cloth)
15+
: (closet[clothType] = [cloth]);
16+
});
17+
18+
return getCombinationNumber(closet) - 1;
19+
};

0 commit comments

Comments
 (0)