We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static List<int> freqQuery(List<List<int>> queries)
{
Dictionary<long, int> res = new Dictionary<long, int>();
List<int> ret = new List<int>();
foreach (List<int> query in queries)
{
switch(query[0])
{
case 1:
if (!res.ContainsKey(query[1]))
{
res.Add(query[1], 1);
} else
{
res[query[1]]++;
}
break;
case 2:
if (res.ContainsKey(query[1]))
{
if (res[query[1]] == 1)
{
res.Remove(query[1]);
}
else
{
res[query[1]]--;
}
}
break;
case 3:
int y = 0;
if (res.Values.Contains(query[1])) { y = 1; }
ret.Add(y);
break;
}
}
return ret;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
c#