예제 #1
0
 internal PrefixTreeNode(PrefixTreeNode parent, char letter)
 {
     _parent = parent;
     _children = new List<PrefixTreeNode>();
     _isWord = false;
     _letter = letter;
 }
예제 #2
0
        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();
        }
예제 #3
0
 public PrefixTree()
 {
     _root = new PrefixTreeNode(null, '\0');
 }