프로그래머스 - 위장 - Level 2

Byungwoong An·2021년 6월 26일
0

문제

풀이전략

  1. 결국 한 종류의 옷을 입건 말거나이다. 따라서 먼저 같은 카테고리의 옷은 더해주어 모든 카테고리의 갯수를 찾고, 이를 모두 곱해주고 1을 빼준다. 여기서 1을 빼주는 것은 모든 것을 입지 않을 경우이다.

코드

#include <string>
#include <vector>
#include <unordered_map>
#include <utility>
using namespace std;

int solution(vector<vector<string>> clothes) {
    int answer = 1;
    unordered_map<string,int> ump;
    
    for(int i=0; i<clothes.size(); i++){
        ump[clothes[i][1]] += 1;
    }
    for(pair<string, int> p: ump){
        answer *= (p.second + 1);
    }
    
    return answer-1;
}
profile
No Pain No Gain

0개의 댓글