공부/C#

[C#] 프로그래머스 해시 - 의상

굴러다니다니 2025. 3. 13. 23:59

https://school.programmers.co.kr/learn/courses/30/lessons/42578

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

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>();
        for (int i = 0; i < clothes.GetLength(0); i++){
            if(!dic.ContainsKey(clothes[i, 1])){
                dic[clothes[i, 1]] = 1;
            }
            else{
                dic[clothes[i, 1]]++;
            }
        }
        foreach (var a in dic){
            answer *= (a.Value + 1);
        }
        answer -= 1;
        return answer;
    }
}
728x90
반응형