코딩테스트_c#/프로그래머스
프로그래머스 ) 의상 Level.2_C#
노년인생
2024. 11. 27. 16:28
728x90
반응형
의상 문제
내 코드
using System;
using System.Collections.Generic;
public class Solution {
public int solution(string[,] clothes) {
int answer = 1;
Dictionary<string, int> dic = new Dictionary<string, int>();
dic.Add(clothes[0, 1], 0);
for (int i = 0; i < clothes.GetLength(0); i++)
{
if(dic.ContainsKey(clothes[i, 1]))
{
dic[clothes[i, 1]]++;
}
else
{
dic.Add(clothes[i, 1],1);
}
}
foreach(string key in dic.Keys)
{
// *(한옷의 종류 수 +1(안입는 경우의 수))
answer *= dic[key] + 1;
}
answer -= 1; // - 아무것도 안입는 경우의 수
return answer;
}
}
728x90
반응형