https://school.programmers.co.kr/learn/courses/30/lessons/42578
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
기억해야할점
첫번째, 아이디어를 간단하게 생각합니다.
예시1번을 봅니다.
headgear 가 yellow hat, gree_turban, none (없는경우)
eyewear 가 blue_sunglaesses, none(없는경우) 이렇게 생각하면
3*2 - 1 (none, none이면 -1 해야합니다) 이니 = 5 이렇게 나옵니다.
import java.util.*; class Solution { HashMap<String, Integer> hashmap = new HashMap<String, Integer>(); public int solution(String[][] clothes) { int answer = 0; //1. 옷을 종류별로 구분합니다. for(int i=0;i<clothes.length;i++){ String type = clothes[i][1]; hashmap.put(type, hashmap.getOrDefault(type, 0) + 1); } //2. 입지 않는 경우를 추가해서 모든 조합을 계산합니다. answer = 1; for(Map.Entry<String, Integer> entry : hashmap.entrySet()){ answer *= entry.getValue() + 1; } answer -= 1; return answer; } }
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스]기능개발- 구현 (0) | 2023.02.02 |
---|---|
[프로그래머스]베스트앨범 - 해쉬 + 우선순위큐 (0) | 2023.02.02 |
[프로그래머스]전화번호 목록 - 해쉬 + 아이디어 (0) | 2023.01.28 |
[프로그래머스]이진 변환 반복하기 - 문자열 + StringBuilder (0) | 2023.01.25 |
[프로그래머스]괄호 회전하기 - 구현 + 스택 (0) | 2023.01.23 |