using System.Collections.Generic;
private HashSet<string> hashSet = new();
public MyDictionary(IEnumerable<string> words)
for(int i=0;i<w.Length;i++)
hashSet.Add(w.Substring(0,i) + "*" + w.Substring(i+1, w.Length-i-1));
public bool IsInDict(string word)
return hashSet.Contains(word);
public static void Main()
var myDictionary = new MyDictionary(new string[] {"cat", "car", "bar", "bat", "dog", "zebra" });
Debug.Assert(myDictionary.IsInDict("cat") == true);
Debug.Assert(myDictionary.IsInDict("don") == false);
Debug.Assert(myDictionary.IsInDict("caz") == false);
Debug.Assert(myDictionary.IsInDict("bat") == true);
Debug.Assert(myDictionary.IsInDict("zebra") == true);
Debug.Assert(myDictionary.IsInDict("ca*") == true);
Debug.Assert(myDictionary.IsInDict("c*t") == true);
Debug.Assert(myDictionary.IsInDict("*at") == true);
Debug.Assert(myDictionary.IsInDict("da*") == false);
Debug.Assert(myDictionary.IsInDict("*ag") == false);
public static void Assert(bool a, [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
throw new Exception($"Test failed, line {sourceLineNumber}");