You are viewing a single comment's thread. Return to all comments →
in C#
public static void checkMagazine(List<string> magazine,List<string> note) { var dictionaryMagazine = new Dictionary<string, int>(); var dictionaryNote = new Dictionary<string, int>(); foreach(var word in magazine){ if(dictionaryMagazine.ContainsKey(word)){ dictionaryMagazine[word] +=1; }else{ dictionaryMagazine.Add(word, 1); } } foreach(var word in note){ if(dictionaryNote.ContainsKey(word)){ dictionaryNote[word] +=1; }else{ dictionaryNote.Add(word, 1); } } foreach (KeyValuePair<string, int> word in dictionaryNote) { if(!dictionaryMagazine.ContainsKey(word.Key)){ Console.WriteLine("No"); return; }else if(word.Value>dictionaryMagazine[word.Key]){ Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
in C#