알고리즘
[알고리즘] 위장
keel_im
2021. 3. 11. 12:17
반응형
포인트
- 해시를 사용하여 종류의 수를 계산해서 조합을 구하는 함수를 구현하는 것입니다.
- 먼저 종류의 개수를 세어서 저장을 합니다
🧶문서는 항상 수정될 수 있습니다. 비판은 환영합니다.
c++/cpp
#include <bits/stdc++.h>
using namespace std;
int solution(vector<vector<string>> clothes)
{
int answer = 1;
unordered_map<string, int> data;
for (auto clothe : clothes)
{
data[clothe[1]] += 1;
}
for (auto it = data.begin(); it != data.end(); it++)
{
answer *= it->second + 1;
}
answer-=1;
return answer;
}
python
def solution(clothes):
data = dict()
for clothe in clothes:
data[clothe[1]] = data.get(clothe[1], 0) + 1
answer = 1
for ele in data.values():
answer *= (ele+1)
print(answer)
answer -= 1
return answer
반응형