내일배움캠프 44일차 TIL _ 10주 1일차
2024. 6. 17. 21:54ㆍTIL Java
- 오늘 있었던 일
- 팀과제
- 알고리즘
SPRIONG
- 스프링 정리
알고리즘 문제 풀기
● 의상
더보기
● 의상 //링크
import java.util.HashMap;
import java.util.Map;
class Solution {
public int solution(String[][] clothes) {
Map<String,Integer> map = new HashMap<>();
for (String[] row : clothes) {
map.put(row[1], map.getOrDefault(row[1], 0) + 1);}
int[] n = map.values().stream().mapToInt(i -> i).toArray();
int answer = 1;
for( int a : n){
answer *= a+1;
}
answer -= 1;
return answer;
}
}
- 문제 지문에
-
face에 해당하는 의상이 crow_mask, blue_sunglasses, smoky_makeup이므로 아래와 같이 3개의 조합이 가능합니다.
-
-
- (a + 1)(b + 1)(c + 1)...(해당 종류 옷의 수 + 1) -1 을 계산하면 된다는 글을 보고 맞춰서 해봤더니 됐다.
- 밑은 다른 사람의 풀이
-
import java.util.*; import static java.util.stream.Collectors.*; class Solution { public int solution(String[][] clothes) { return Arrays.stream(clothes) .collect(groupingBy(p -> p[1], mapping(p -> p[0], counting()))) .values() .stream() .collect(reducing(1L, (x, y) -> x * (y + 1))).intValue() - 1; } }
- 에?
당일 회고
- 깃 어려워... 태스트 어려워....
'TIL Java' 카테고리의 다른 글
내일배움캠프 46일차 TIL _ 10주 3일차 (0) | 2024.06.19 |
---|---|
내일배움캠프 45일차 TIL _ 10주 2일차 (0) | 2024.06.18 |
내일배움캠프 43일차 TIL _ 9주 5일차 (0) | 2024.06.14 |
내일배움캠프 42일차 TIL _ 9주 4일차 (0) | 2024.06.13 |
내일배움캠프 41일차 TIL _ 9주 3일차 (0) | 2024.06.12 |