//구글콘솔 광고 추가가
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
반응형

+ Recent posts