-
Notifications
You must be signed in to change notification settings - Fork 35
/
HashTablesRansomNote.cs
53 lines (42 loc) · 1.28 KB
/
HashTablesRansomNote.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Hash Tables: Ransom Note
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution
{
// Complete the checkMagazine function below.
static void checkMagazine(string[] magazine, string[] note)
{
var dic = new SortedDictionary<string, int>();
foreach (var group in magazine.GroupBy(x => x))
dic.Add(group.Key, group.Count());
foreach (var word in note.GroupBy(x => x))
{
if(!dic.TryGetValue(word.Key, out int count) || word.Count() > count)
{
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
static void Main(string[] args)
{
string[] mn = Console.ReadLine().Split(' ');
int m = Convert.ToInt32(mn[0]);
int n = Convert.ToInt32(mn[1]);
string[] magazine = Console.ReadLine().Split(' ');
string[] note = Console.ReadLine().Split(' ');
checkMagazine(magazine, note);
}
}