internal PrefixTreeNode(PrefixTreeNode parent, char letter) { _parent = parent; _children = new List<PrefixTreeNode>(); _isWord = false; _letter = letter; }
private string[] Solve(WordRack originalRack, PrefixTreeNode root) { List<string> words = new List<string>(); foreach (char character in originalRack.AvailableLetters) { WordRack rack = originalRack.Clone(); PrefixTreeNode node = root.Children.FirstOrDefault(x => x.Letter == character); if (node != null) { rack.Consume(character); if (node.IsWord) { words.Add(node.GetWord()); } string[] result = this.Solve(rack, node); if (result != null && result.Length > 0) { words.AddRange(result); } } } return words.ToArray(); }
public PrefixTree() { _root = new PrefixTreeNode(null, '\0'); }