🎈 풀이 방법
키를 string으로 하는 딕셔너리를 사용하면 쉽게 해결할 수 있는 문제였다.
using System;
using System.Collections.Generic;
public class Solution {
public int solution(string[] want, int[] number, string[] discount)
{
int answer = 0;
Dictionary<string, int> wantList = new Dictionary<string, int>();
for (int i = 0; i < want.Length; ++i)
wantList[want[i]] = number[i];
Dictionary<string, int> discountList = new Dictionary<string, int>();
for (int j = 0; j <= discount.Length - 10; ++j)
{
discountList.Clear();
for (int i = 0; i < 10; ++i)
{
if (discountList.ContainsKey(discount[j + i]))
discountList[discount[j + i]]++;
else
discountList[discount[j + i]] = 1;
}
bool membership = true;
for (int i = 0; i < want.Length; ++i)
{
if (discountList.ContainsKey(want[i]) == false || wantList[want[i]] != discountList[want[i]])
{
membership = false;
break;
}
}
if (membership)
answer++;
}
return answer;
}
}