public class Solution { public bool IsAnagram(string s, string t) { Dictionary<char, int> dic = new Dictionary<char, int>(); foreach (var c in s) { if (!dic.ContainsKey(c)) { dic.Add(c, 1); } else { dic[c]++; } } foreach (var c in t) { if (!dic.ContainsKey(c)) { return false; } else { dic[c]--; } } foreach (var d in dic) { if (d.Value != 0) { return false; } } return true; } }