anott
기록
anott
  • 분류 전체보기
    • 오라클
    • SQL
    • 알고리즘
      • 백준저지
      • 프로그래머스
      • SWEA
    • 개발 관련
    • 프론트엔드
      • TypeScript, Next.js
      • React 공식문서 읽기
hELLO · Designed By 정상우.
anott

기록

알고리즘/프로그래머스

프로그래머스 위장

2021. 8. 18. 23:30

출처: 프로그래머스 코딩 테스트 연습 https://programmers.co.kr/learn/courses/30/lessons/42578

 

코딩테스트 연습 - 위장

 

programmers.co.kr

 

 

생각

백준저지의 패션왕 신해빈(https://www.acmicpc.net/problem/9375)과 동일한 문제다.

 

 

코드

import java.util.HashMap;
class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        HashMap<String,Integer> cloth = new HashMap<>();
        for(int i=0; i<clothes.length; i++) {
            cloth.put(clothes[i][1], cloth.getOrDefault(clothes[i][1],0)+1);
        }
        for(int c: cloth.values()) {
            answer = answer * (c+1);
        }
        answer--;
        
        return answer;
    }
}
저작자표시 비영리 (새창열림)

'알고리즘 > 프로그래머스' 카테고리의 다른 글

프로그래머스 뉴스 클러스터링  (0) 2021.09.21
프로그래머스 메뉴 리뉴얼  (0) 2021.09.13
프로그래머스 순위 검색  (0) 2021.09.09
프로그래머스 구명보트  (0) 2021.09.07
프로그래머스 거리두기 확인하기  (0) 2021.08.31
    '알고리즘/프로그래머스' 카테고리의 다른 글
    • 프로그래머스 메뉴 리뉴얼
    • 프로그래머스 순위 검색
    • 프로그래머스 구명보트
    • 프로그래머스 거리두기 확인하기
    anott
    anott

    티스토리툴바