728x90
https://school.programmers.co.kr/learn/courses/30/lessons/42578
(1) C++
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
map<string, int> m;
for(int i = 0; i < clothes.size(); i++){
m[clothes[i][1]]++;
}
for(auto it:m){
answer *= (it.second + 1);
}
return answer - 1;
}
(2) Python
def solution(clothes):
answer = 1
clothes_dict = {}
for cloth in clothes:
if cloth[1] not in clothes_dict:
clothes_dict[cloth[1]] = list()
clothes_dict[cloth[1]].append(cloth[0])
continue
clothes_dict[cloth[1]].append(cloth[0])
for cloth in clothes_dict:
answer *= len(clothes_dict[cloth]) + 1
return answer - 1
728x90
'Study > Coding Test' 카테고리의 다른 글
[프로그래머스] 입국심사 Python, C++ (0) | 2023.08.01 |
---|---|
[프로그래머스] 베스트앨범 Python, C++ (0) | 2023.08.01 |
[프로그래머스] K번째수 Python, C++ (0) | 2023.08.01 |
[프로그래머스] 게임 맵 최단거리 Python, C++ (0) | 2023.07.31 |
[프로그래머스] 네트워크 Python, C++ (0) | 2023.07.31 |