Skip to content

Commit 3f4a309

Browse files
committed
[level 2] Title: 의상, Time: 0.36 ms, Memory: 85.1 MB -BaekjoonHub
1 parent 1bd550f commit 3f4a309

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

프로그래머스/2/42578. 의상/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 85.7 MB, 시간: 0.12 ms
7+
메모리: 85.1 MB, 시간: 0.36 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 04월 16일 16:19:15
19+
2025년 09월 01일 15:53:56
2020

2121
### 문제 설명
2222

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import java.util.*;
22
class Solution {
3-
public int solution(String[][] clothes) {
4-
Map<String,Integer> map = new HashMap<>();
5-
// 종류별로 그룹화 , 기본값:1(아무것도 안입는 경우 포함: +1)
6-
for(int i=0;i<clothes.length;i++){
7-
String category = clothes[i][1];
8-
map.put(category,map.getOrDefault(category,1)+1);
3+
HashMap<String,Integer> map = new HashMap<>();
4+
public int solution(String[][] clothes) {
5+
for(String[] cloth: clothes){
6+
String type = cloth[1]; // 의상 종류
7+
// 의상 종류 별 가짓수 기록
8+
map.put(type,map.getOrDefault(type,0) +1);
99
}
10-
11-
int answer = 1;
12-
for(int num:map.values()){
13-
answer *= num;
10+
11+
int[] number = new int[map.size()];
12+
int idx = 0;
13+
int total = 1;
14+
for(String key : map.keySet()){
15+
int value = map.get(key);
16+
number[idx++] = value;
17+
total *= value + 1;
1418
}
15-
16-
// 모든 종류의 옷을 안입는 경우 -1
17-
answer--;
18-
return answer;
19+
20+
return total-1;
1921
}
2022
}

0 commit comments

Comments
 (0)