3.2.43 #
解答 #
依照题意实现即可,put/get 大约 10 倍差距。
MostFrequentlyKey
的实现:
public static TKey MostFrequentlyKey<TKey>(IST<TKey, int> st, TKey[] keys)
{
foreach (var s in keys)
{
if (st.Contains(s))
st.Put(s, st.Get(s) + 1);
else
st.Put(s, 1);
}
var max = keys[0];
foreach (var s in st.Keys())
if (st.Get(s) > st.Get(max))
max = s;
return max;
}